How to convert milliseconds to date object ?

I tried doing this....why do I get the same Date value for diffrent long values

System.out.println("COOKIE EXPIRY DATE - Converting from long value : "+ new Date(1147676097091L));
System.out.println("COOKIE EXPIRY DATE - Converting from long value : "+ new Date(1147676097000L));

COOKIE EXPIRY DATE - Converting from long value : Mon May 15 12:24:57 GMT+05:30 2006
COOKIE EXPIRY DATE - Converting from long value : Mon May 15 12:24:57 GMT+05:30 2006
vaibhavbajpaiAsked:
Who is Participating?
 
CEHJConnect With a Mentor Commented:
>>why do I get the same Date value for diffrent long values

Because 91 milliseconds difference is insignificant
0
 
AstaedusCommented:
because the difference is only 91 milliseconds and you only display seconds?
0
 
CEHJCommented:
Sorry Astaedus - didn't see your post
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
objectsCommented:
try:

System.out.println("COOKIE EXPIRY DATE - Converting from long value : "+ new Date(1147676098091L));
System.out.println("COOKIE EXPIRY DATE - Converting from long value : "+ new Date(1147676097000L));
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Try:

Date d1 = new Date ( 1147676098091L ) ;
Date d2 = new Date ( 1147676097000L ) ;
System.out.println ( d1.equals ( d2 ) ) ; // or d1.compareTo ( d2 ) ; or d2.after ( d1 ) ;
0
 
Giant2Commented:
In addiction to te before:
Try to do this:

java.text.Format formatter = new java.text.SimpleDateFormat("E M dd hh:mm:ss.SSS z yyyy ");
String s1 = formatter.format(new Date(1147676097091L));
String s2 = formatter.format(new Date(1147676097000L));

they contains the date fully (with milliseconds).
See here for the meaning of format char:
http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html

Hope this could help you.
Bye, Giant.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.