2

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?

2
  • 1382482802615 is too large to fit into a 32-bit int. You need a long: 1382482802615L. Commented Nov 2, 2013 at 11:34
  • I receive the above data as a string so do you mean 1382482802615 as string Commented Nov 2, 2013 at 11:48

1 Answer 1

4

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.