• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why is printing "000" as milliseconds,See the code  RSS feed

 
Punya Pratap Singh
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Calendar newDate = Calendar.getInstance();
SimpleDateFormat df = (SimpleDateFormat)SimpleDateFormat.getInstance();
df.applyPattern("yyyy MMM dd HH:mm:ss");
Date date = df.parse("1982 Apr 17 16:46:23");
newDate.setTime(date);
long preSysMillis = newDate.get(Calendar.MILLISECOND);
System.out.println("PreMilliseconds First " + preSysMillis);

Please help.

 
Punya Pratap Singh
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I forget to write notation for milliseconds.
 
Karanjeet Kareer
Greenhorn
Posts: 3
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hello Punya,

Try the following, i think thats what you want ??

df.applyPattern("yyyy MMM dd HH:mm:ss.SSS");
Date date = df.parse("1982 Apr 17 16:46:20.123");

Thanks
Karan
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16057
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags when you post source code.

Note that you can write the following lines in a simpler way:


You can just do:

No need to use the getInstance() factory method.
 
Punya Pratap Singh
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Jesper de Jong.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!