File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Different output converting dates to msecs!

 
Alessandro Camel
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have really some problems with the Date Class!

The aim is to manage timestamp in msec, in order to store them
in a sql db so I can use the BETWEEN clause.



I try this code:



and the output is:



The problem is the second line of output, I was expecting the same long number as the others!
Why the difference ?
 
John Jai
Rancher
Posts: 1776
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you format from the milli seconds check if there is any GMT addition in the date by giving like below.
 
Alessandro Camel
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Jai wrote:When you format from the milli seconds check if there is any GMT addition in the date by giving like below.


Thanks for the reply!
In my project I never need to store the time, I only care about the date.
Any advice to get rid of these problems when I am using ms, since I don't care about the time ?
 
Raphael Onofre
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alessandro Camel wrote:
John Jai wrote:When you format from the milli seconds check if there is any GMT addition in the date by giving like below.


Thanks for the reply!
In my project I never need to store the time, I only care about the date.
Any advice to get rid of these problems when I am using ms, since I don't care about the time ?


Which problem? The GMT addition?
 
Alessandro Camel
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raphael Onofre wrote:
Alessandro Camel wrote:
John Jai wrote:When you format from the milli seconds check if there is any GMT addition in the date by giving like below.


Thanks for the reply!
In my project I never need to store the time, I only care about the date.
Any advice to get rid of these problems when I am using ms, since I don't care about the time ?


Which problem? The GMT addition?


Yes, this and every problem could be in place when using data/time strings when I care only only about the data..
 
Raphael Onofre
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Brazil(my country) is used (GMT-3).

So, if i have to get the correct time in Java we can do:

3h = 10800000 millisec

Thus,


 
Campbell Ritchie
Sheriff
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is worth looking at the TimeUnit enum, which might make such calculations easier.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic