2 Replies Latest reply: Nov 5, 2012 1:50 PM by jschellSomeoneStoleMyAlias RSS

    DB timestamp value with JVM TimeZone


      Hi all,

      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.

      For how to do the conversion, do you have any suggestion?

        • 1. Re: DB timestamp value with JVM TimeZone
          Make myself more understood, I want to convert java.sql.Timestamp("1970-0101T16:00:00+8:00") from database to java.util.Timestamp("1970-01-01T16:00:00*UTC*"). The literal is same.
          • 2. Re: DB timestamp value with JVM TimeZone
            Seems like an odd request.
            1. If your database does NOT specify a timezone then the jdbc connection string would have a way to do that explicitly.
            2. If you database DOES specify a timezone then you would need to write SQL (not java) that returned a unspecified timezone value, probably a string, which you would use to create a java timestamp (for example via SimpleDateFormat).

            The above or course presumes that you understand that the jdbc has perfectly acceptable ways of getting correct timestamps from databases and that displaying a timestamp value has nothing to do with that.