Search code examples
javadatevb6

Java Date toString contains a timezone... Why?


I wrote some code today in VB6 which would get me the number of milliseconds since 1/1/1970, so I could then send the value off to a java application which would parse that value like new Date(Long.parse(milliseconds)). I understand that the milliseconds the Date(Long) is looking for is the number of milliseconds since epoch in GMT. The machine I am running on is on CDT here in the US. When I get the toString value of the date parsed from the milliseconds, this is the value I get:

Tue Aug 11 15:40:50 CDT 2015

Is the CDT just there because the local machines timezone is CDT? I just think its a little weird that the constructor for Date would assume that a date derived from the milliseconds since epoch in GMT would implicitly be in the local machines timezone, rather than being offset (in this case) by -5 hours.


Solution

  • Is the CDT just there because the local machines timezone is CDT?

    The timezone for display purposes is based on the default time zone.

    The millis in the Date is relative to epoch and it doesn't have a time zone of its own.

    It is taken since 00:00 1/1/1970 GMT or if you prefer 17:00 12/31/1969 CDT.

    would implicitly be in the local machines timezone

    The use of the local time zone is for display purposes only. Use another time zone or serialize the Date and send it to a machine in another timezone and it will use the local timezone again.