Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Formatting Date

Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am facing some problem while formatting the date.

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.
Posts: 70266
  • 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"!
Posts: 21999
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic