aspose file tools*
The moose likes Beginning Java and the fly likes Different output converting dates to msecs! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Different output converting dates to msecs!" Watch "Different output converting dates to msecs!" New topic
Author

Different output converting dates to msecs!

Alessandro Camel
Ranch Hand

Joined: Jul 03, 2009
Posts: 35
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
Bartender

Joined: May 31, 2011
Posts: 1776
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

Joined: Jul 03, 2009
Posts: 35
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

Joined: Dec 29, 2011
Posts: 8
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

Joined: Jul 03, 2009
Posts: 35
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

Joined: Dec 29, 2011
Posts: 8
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

Joined: Oct 13, 2005
Posts: 36453
    
  15
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
 
subject: Different output converting dates to msecs!
 
Similar Threads
java.text.SimpleDateFormat does not behaves as expected
Date function
problems with String to Date Converter
Help in converting date from string
Convert String to Date format