• Post Reply Bookmark Topic Watch Topic
  • New Topic

Date Format in JAVA  RSS feed

 
Saurabh Agrawal
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I am required to display the current date in the following format:

15th January, 2007

How can it be done using SimpleDateFormat ?

I am able to get 15 January 2007 12:04:02 using the following pattern:

dd MMMMM yyyy HH:mm:ss

But as per the date, I need to append th, nd,st, etc.

Is there any way out by which i can get the date in above mentioned format?


Thanks in advance,
Saurabh
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it is not in the API documentation of SimpleDateFormat, then you can safely assume that SimpleDateFormat does not have this kind of functionality. So if you really must have this (adding "th", "nd", "st" etc. after the number), you'll just have to put your brain to work and invent something yourself.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not an advanced question. Moving...
 
Saurabh Agrawal
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jesper Young:
If it is not in the API documentation of SimpleDateFormat, then you can safely assume that SimpleDateFormat does not have this kind of functionality. So if you really must have this (adding "th", "nd", "st" etc. after the number), you'll just have to put your brain to work and invent something yourself.


Is there any other way of achieving this? Any API that can be used instead of reinventing the wheel?

Thanks in advance,
Saurabh
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not using SimpleDateFormat. You'll probably need to implement your own DateFormat to do this.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!