0

I'm trying to convert timestamps to date, I got this exception:

java.text.ParseException: Unparseable date: "1604328483716" 
 at java.base/java.text.DateFormat.parse(DateFormat.java:395)

All the timestamps values that I have, having a format like this 1604328483716

Dom
  • 59
  • 5
  • 1
    Please don't use `Date` and `SimpleDateFomat`. They're obsolete and [troublesome](https://stackoverflow.com/q/1969442/507738). Use classes from the `java.time` package instead, as T.J. Crowder already mentioned in his answer. – MC Emperor Mar 01 '21 at 13:53

2 Answers2

3

Your formatter is set up to handle the format "EEE, d MMM yyyy HH:mm:ss Z". "1604328483716" isn't remotely in that format.

The value "1604328483716" looks like the string version of a milliseconds-since-The-Epoch value. If so, convert it to a long (Long.parseLong) and use new Date(theLongValue), which will give you a Date instance for Monday November 2nd 2020 14:48:03 GMT (or whatever that is in your local timezone).

You might also consider using the newer date/time API in the java.time package, rather than java.util.Date.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
0

1604328483716

It is timestamp: https://www.unixtimestamp.com/?ref=dtf.ru

So, simply do:

long modificationTime = rec.getJsonNumber("modificationTime").lngValue();
Date date = new Date(modificationTime);
S. Kadakov
  • 861
  • 1
  • 6
  • 15