jQuery in Action, 2nd edition*
The moose likes JDBC and the fly likes DB timestamp value with JVM TimeZone Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "DB timestamp value with JVM TimeZone " Watch "DB timestamp value with JVM TimeZone " New topic
Author

DB timestamp value with JVM TimeZone

Ricky Ru
Greenhorn

Joined: Nov 05, 2012
Posts: 1
Dears,

If we have database timestamp "1970-01-01T16:00:00", no matter what Time Zone the jvm is running with, we get the java.sql.Timestamp object representing the time "1970-01-01T16:00:00" locally(Shang Hai, Las Vegas, London...). So, the UTC time will be different as well.

I need to do some conversion work to make database timestamp "1970-01-01T16:00:00" as UTC time. Although it will be different in jvms with different time zones, they all mean the same time(UTC time, same million seconds from UTC Time 1970-01-01T00:00:00.000) and will be consistent.

So, do you know how to convert a local java.sql.Timestamp to a UTC timestamp?(Actually, they're two different times.) For example, I want to convert java.sql.Timestamp("1970-0101T16:00:00+8:00") from database to java.util.Timestamp("1970-01-01T16:00:00UTC"). The literals are same.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: DB timestamp value with JVM TimeZone
 
Similar Threads
Dealing with results of java time code
convert database date object in to java string object
epoch is wrong
Date class related query
System.currentTimeMillis() is not UTC in Milliseconds since 1.1.1970 ! Official JavaDoc wrong?