• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Formatting Date

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi..
I am facing some problem while formatting the date.


sdf.setTimeZone(TimeZone.getTimeZone("EST"))
java.util.Date d=sdf.parse(Edate.substring(0,10));
Date nd=new Date(d);

I cant use format coz i have to this date in a method with date asargument

Now Im getting the date in the format mm/dd/yy.But i want date in the format yyyy/mm/dd so that i could differentiate between 2001 and 1901.


Thanks in advance.
 
Marshal
Posts: 79469
379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
More of a beginner's question.

Go to the API documentation for SimpleDateFormat (which I presume is what sdf is) and it tells you all the different sort of formats you can use.

Just be careful; somebody last week had problems because they were using "m" rather than "M"!
 
Sheriff
Posts: 22787
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are getting the date without the century, there is no possible way to distinguish between 1901 and 2001 - since they're both 01. So you'll need to address the source and make it include the century as well if you need it.

It's like trying to get 4 apples if I only give you 2. Ok, bad example, you can always grow an apple tree, but you get the picture
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic