File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes SimpleDateFormat and Ordinals Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "SimpleDateFormat and Ordinals" Watch "SimpleDateFormat and Ordinals" New topic
Author

SimpleDateFormat and Ordinals

Rik Sweeney
Ranch Hand

Joined: Sep 04, 2001
Posts: 36
I'm using SimpleDateFormat to change a date into the format
dd MMMM yyyy
to produce, say,
29 May 2002
Is there any easy way to add on the date ordinal? So in this case it would be
29th May 2002?
Thanks
Irene Loos
Ranch Hand

Joined: Apr 15, 2002
Posts: 78
You can get a string from your SimpleDateFormat and reformat it. Try this:

[ June 19, 2002: Message edited by: Irene Loos ]

Irene Loos
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Don't forget that "th" is not the only suffix. I don't see a way to use SimpleDateFormat to do this. I'd use Calendar to extract the day of the month, and switch on the last digit to determine whether to add "st", "nd", "rd", or "th".


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SimpleDateFormat and Ordinals
 
Similar Threads
How to produce Oct 29, 2001 03:50:15 GMT
date
string to date conversion problem
How to find day from the week using date format?
How to Compare two Calendar Objects.