1

I am getting error out-of-range when I was trying to convert timestamp into date format.

long timeStamp = 1342049220104;
Timestamp stamp = new Timestamp(timeStamp);
Date date = new Date(stamp.getTime());
System.out.println(date);

The error that I got "The literal 1342049220104 of type int is out of range".

Sultan
  • 189
  • 1
  • 9

2 Answers2

2

You have to write it like this, with an L character appended:

long timeStamp = 1342049220104L;

Otherwise your literal number is interpreted as a 32-bit int rather than a 64-bit long.

See Tutorial to learn more about Java primitive values.

Basil Bourque
  • 262,936
  • 84
  • 758
  • 1,028
Nitek
  • 2,395
  • 2
  • 22
  • 39
0
long timeStamp = 1342049220104L; 

See javadoc, you can use:

new Date(timeStamp);