Reputation: 187
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".
Upvotes: 1
Views: 3860
Reputation: 2614
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.
Upvotes: 2
Reputation: 36
long timeStamp = 1342049220104L;
See javadoc, you can use:
new Date(timeStamp);
Upvotes: 0