sid
sid

Reputation: 98

Parsing js timestamp in java

I have a timestamp of the format 1382482802615, which I receive from some js code like this:

    new Date().getTime()

I need to parse the above timestamp in java. I receive the above data as a string. I am unable to do the following, which throws a out of range compilation error.

    Date date = new Date(1382482802615);

But if I do something like this:

    Date date = new Date();
    System.out.println(date.getTime());

It prints 1383391655609, which contains the same number of digits.

What am I doing wrong? Or how do I parse something like 1382482802615 into a date in java?

Upvotes: 2

Views: 1805

Answers (1)

Masudul
Masudul

Reputation: 21981

Without L the value was int by default and exceed the limit of Integer.MAX_VALUE. Add L to convert int value as long.

 Date date = new Date(1382482802615L);

Upvotes: 4

Related Questions