开发者

date format in android

I am stuck in one date format

i want my date should look like this, 18th Mar 2011 and it can be 1st, 2开发者_如何学运维nd,3rd that means i want to resolve for all the aspects

Plz help me out for this ASAP

Thanks in advance to all.


I think you want to change date in a 18th, 2nd, 1st, 3rd dated way, if i am not wrong then you can use simpleDateFormat class to convert date in different formats.

Before using SimpleDateFormat, just refer the SDK documentation: http://developer.android.com/reference/java/text/SimpleDateFormat.html.

To have day number with nd, th, rd (i.e. 2nd, 4th, 3rd, etc.), you can use:

F - day of week in month (Number) - 2 (2nd Wed in July) (given in the documentation).

For example using SimpleDateFormat:

String dateStr = "03/08/2010"; 

SimpleDateFormat curFormater = new SimpleDateFormat("dd/MM/yyyy"); 
Date dateObj = curFormater.parse(dateStr); 
SimpleDateFormat postFormater = new SimpleDateFormat("MMMM dd, yyyy"); 

String newDateStr = postFormater.format(dateObj); 


This is the term you are looking for: Quantity Strings (Plurals)

here is a link for it in the documentation: Plurals

Here is a link with examples:

Examples

And One more: Android Pluralization not working, need help

Hope this helps. so you just need to reformat the string with the date by using the examples provided and thats it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜