• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Date Format in JAVA

 
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not an advanced question. Moving...
 
Saurabh Agrawal
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not using SimpleDateFormat. You'll probably need to implement your own DateFormat to do this.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic