• Post Reply Bookmark Topic Watch Topic
  • New Topic

SimpleDateFormat  RSS feed

 
Maurice Le Chat
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • 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.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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".
 
Supun Lakshan Dissanayake
Ranch Hand
Posts: 143
Android Java Linux
  • Mark post as helpful
  • send pies
  • 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
  • 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!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!