• Post Reply Bookmark Topic Watch Topic
  • New Topic

formatting dates  RSS feed

 
Jay Ram
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have date time in string as yyyymmddhhmmssss.
I need in the format yyyy-mm-dd hh:mm:ssss

I tried
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmssss");
java.util.Date date = sdf.parse(ts);
System.out.println("date?? " + ts + " " + date.toString());

But this prints the date right; but the time, i guess it treats as milliseconds and converts that time to another time.
for eg: 2006120713274913 gets converted to 2006-12-07 14:48:53.0

How do I solve this problem?

Thanks,
Jay.
 
Joe Ess
Bartender
Posts: 9439
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where are you getting four digits of seconds? My minutes only have 60 seconds. I bet your time actually has milliseconds and you should parse it accordingly.
 
Jay Ram
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats a hit on my head
Sometimes, my brain stops working.. i guess this is one of the times..

Thanks for yr response though!!

Jay.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!