• 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

SimpleDateFormat

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can someone please tell me why the following simple program does not output the expected results:


Output is:
date 1:Tue Jan 17 14:53:15 CET 2012
date 2:Wed Jan 23 11:53:15 CET 2013

From String DATE_STR_1 I would expect December and from DATE_STR_2 I would rather expect August.
However we have Jan for both cases!

Hwo knows about this strange bug?
Thanks in advance.
 
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have a look again at the SimpleDateFormat documentation. Is "DD" really what you want in that pattern? You might want to try "dd".
 
Ranch Hand
Posts: 143
Android Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Maurice Le Chat wrote:


DD means day in year.
so 23 is 23rd of January.
dd means day of month.
so use dd instead for DD.
 
Maurice Le Chat
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

You're right. "DD" was typo I didn't see at the moment. DATE_FORMAT_STR = "yyyy-MM-dd HH:mm:ss" results in the expected result.

Thanks. More eyes see more, confirmed once again. Nevertheless the outcome of "jan" always due to this typo is very strange and confusing!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic