Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Date milliseconds

 
Punya Pratap Singh
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
long time = System.currentTimeMillis();
SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm:ss:ms");

java.util.Date resultdate = new java.util.Date(time);
//java.util.Date resultdate1 = sdf.format(time); //returns String I want Date.
// java.util.Date resultdate = sdf.parse(Long.toString(time)); //gives Exception
System.out.println(sdf.format(resultdate));

Prints--Jan 11,2011 11:54:40:5440

I am confused that 999 is the max value for millisecond and value greter than this converts into seconds,then why is it showing 5440 ?

also I want to format "resultdate" into Date again. convering long to String and then formatting It ,is giving format exception
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is "ms" in SimpleDateFormat ?
 
Punya Pratap Singh
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
milliseconds.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Really ? Did you have a look at the API ? Do you see "ms" anywhere ?
 
Punya Pratap Singh
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry Christophe .Its "S"
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. "SSS" should solve your problem
 
Punya Pratap Singh
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Christophe
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"ms" is nothing more than minutes followed by seconds - 54 followed by 40, combining into 5440.
 
Punya Pratap Singh
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, Rob Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic