Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SimpleDateFormat and Ordinals

 
Rik Sweeney
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can get a string from your SimpleDateFormat and reformat it. Try this:

[ June 19, 2002: Message edited by: Irene Loos ]
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic