• Post Reply Bookmark Topic Watch Topic
  • New Topic

Formatting Date  RSS feed

 
Asrita Saran
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • 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.
 
Campbell Ritchie
Marshal
Posts: 56587
172
  • Mark post as helpful
  • send pies
  • 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"!
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!