[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 741
  • Last Modified:

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
0
vaibhavbajpai
Asked:
vaibhavbajpai
1 Solution
 
AstaedusCommented:
because the difference is only 91 milliseconds and you only display seconds?
0
 
CEHJCommented:
>>why do I get the same Date value for diffrent long values

Because 91 milliseconds difference is insignificant
0
 
CEHJCommented:
Sorry Astaedus - didn't see your post
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now