tl;dr
Instant.ofEpochMilli( 170_798_400_000L )
1975-05-31T20:00:00Z
…and…
Instant.ofEpochMilli( 170_798_400_000L )
.atZone( ZoneId.of( "Europe/Moscow" ) )
1975-05-31T23:00+03:00[Europe/Moscow]
See live code.
Using java.time
The modern approach uses the java.time classes in Java 8 and later.
You are using troublesome old date-time classes in Java that are now legacy. Among the many problems on those classes was the well-intentioned but confusing feature of the Date::toString
method applying the current default time zone while generating the string. The internal value is actually always in UTC, but toString
creates the illusion that Date
has a time zone when in fact it does not. That explains your MSK
mystery.
[Even more confusing, there actually is a time zone buried deep in Date
but is irrelevant to this discussion. Those old Date
/Calendar
classes are an awful mess. Fortunately Java now has the best-in-class date-time framework on any platform: java.time.]
Apparently your input represents the number of milliseconds since the Unix epoch of 1970-01-01T00:00:00Z.
The Instant
class represents a moment on the timeline in UTC with a resolution of nanoseconds (up to nine (9) digits of a decimal fraction). This class can directly parse your input number.
Instant instant = Instant.ofEpochMilli( 170_798_400_000L ) ;
instant.toString(): 1975-05-31T20:00:00Z
If you want to see that same moment through the lens of a particular region’s wall-clock time, apply a time zone. Apply a ZoneId
to get a ZonedDateTime
object.
ZoneId z = ZoneId.of( "Europe/Moscow" ) ;
ZonedDateTime zdt = instant.atZone( z ) ;
1975-05-31T23:00+03:00[Europe/Moscow]
JavaScript library is incorrect
The results of your call to the JavaScript library is incorrect with its offset of +04:00. According to Wikipedia, Moscow time from 1930 to 1981 was three hours ahead, +03:00. The java.time framework yields correct results of +03:00 throughout the year of 1975. See Time in Russia for more info. Caveat: I am not expert in Russia/Soviet time.
About java.time
The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as java.util.Date
, Calendar
, & SimpleDateFormat
.
The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
Where to obtain the java.time classes?
The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as Interval
, YearWeek
, YearQuarter
, and more.