No Such Data Type
There is no such thing as "JSON timestamp". JSON has very few defined data types. No date-time types among them.
As the correct Answer by Scary Wombat states, your number is apparently a count of whole seconds from the Unix epoch of 1970. The java.util.Date class tracks time as milliseconds since the Unix epoch, rather than whole seconds. So you need to multiply by 1,000. You also need to deal with long
integers (64-bit) rather than int
(32-bit). Append an uppercase L
to the numeric literals, and declare any variables as long
.
The java.util.Date/.Calendar classes are notoriously troublesome. They are now supplanted by the java.time package built into Java 8 and later, and/or the 3rd-party Joda-Time library.
Various JSON-processing libraries support converters for creating java.time or Joda-Time objects. Or you can perform a conversion in your code, shown below.
Be aware that both java.time and Joda-Time supports assigning a time zone. Code below assigns UTC for demonstration purposes, but you can assign your desired/expected zone.
Joda-Time
Here is some code in Joda-Time 2.8.1 showing the use of your input number as either seconds or milliseconds.
long secondsSinceEpoch = 1419038000L;
DateTime dateTimeSeconds = new DateTime( secondsSinceEpoch , DateTimeZone.UTC );
DateTime dateTimeMillis = new DateTime( secondsSinceEpoch * 1000L , DateTimeZone.UTC ); // Note the crucial "L" appended to the numeric literal.
Dump to console.
System.out.println( "dateTimeSeconds: " + dateTimeSeconds );
System.out.println( "dateTimeMillis: " + dateTimeMillis );
When run.
dateTimeSeconds: 1970-01-17T10:10:38.000Z
dateTimeMillis: 2014-12-20T01:13:20.000Z
java.time
Similar code to above, but using java.time of Java 8.
Instant instant = Instant.ofEpochSecond( 1419038000L );
ZonedDateTime zdtUtc = ZonedDateTime.ofInstant( instant , ZoneOffset.UTC );
ZonedDateTime zdtMontréal = zdtUtc.withZoneSameInstant( ZoneId.of( "America/Montreal" ) );
Dump to console.
System.out.println( "zdtUtc: " + zdtUtc );
System.out.println( "zdtMontréal: " + zdtMontréal );
When run.
zdtUtc: 2014-12-20T01:13:20Z
zdtMontréal: 2014-12-19T20:13:20-05:00[America/Montreal]