Java Timestamp conversion error

Here is my problem with time stamp:

in MySql data base there is a column name creation_date with data type timestamp

the value in the column is 2014-07-04 17:35:07.0 when I am trying to convert it to millisecond using java code, it is showing different behavior

For example

if I fetch it using hibernate and print timestamp.getTime() it is showing 1404484507000

but while doing

Timestamp t=new Timestamp(2014, 7, 4, 17, 35, 7, 0);
System.out.println("t.getTime() - "+t.getTime());

it is showing 61365297907000

What's going wrong here.

Jon Skeet
people
quotationmark

Did you read the documentation for the (deprecated) constructor you're calling? In particular:

year - the year minus 1900
month - 0 to 11

I'd strongly advise you not to call that constructor to start with. If you're using Java 8, use java.time.Instant and then java.sql.Timestamp.fromInstant.

Otherwise, you could call the constructor taking a long (number of milliseconds) and then set the nanos part separately.

Note that a value of 1404484507000 represents 14:35:07 UTC, so presumably your database is performing a time zone conversion.

people

See more on this question at Stackoverflow