aspose file tools*
The moose likes Beginning Java and the fly likes converting from timestamp to date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "converting from timestamp to date" Watch "converting from timestamp to date" New topic
Author

converting from timestamp to date

David J Evans
Greenhorn

Joined: Apr 28, 2006
Posts: 11
Hi,

I have the following method



and to me, it should turn the long number, into whatever date that represents, and this works with some numbers. But when I try it with that number in the example (which I have just chosen arbitrarily), I get the error message(at compile time): integer number too large: 99500000000.

Anyway, I really don't understand why I am getting this error, and only this can sum up how I feel !

Please help!
Rusty Shackleford
Ranch Hand

Joined: Jan 03, 2006
Posts: 490
integers have a maximum size(2^31-1=2147483647) and that number exceeds it. Use an integer that is equal or less then Integer.MAX_VALUE (use this to verify the maximum value).
[ April 28, 2006: Message edited by: Rusty Shackleford ]

"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
David J Evans
Greenhorn

Joined: Apr 28, 2006
Posts: 11
Hi, thanks for you reply.

I realise that the upper limit of an integer may be exceeded by that number, but I thought the long data type was for larger numbers?

Either way, what I want to achieve is turning a timestamp, back into a readable date, which I can do in PHP, so I'm sure java has a function to do it. The timestamp for about 2 minutes ago was this 1146261394418, which is 2 digits longer than the number in my example, but is returned through this function, as a long datatype.



So can anyone explain to me what's going on, or just simply, how I can turn my timestamp back into a human readable date.

Thanks
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
You're using an integer literal instead of a long literal. Change it to 9500000000L and it will work.
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
Technically I should say an "integer literal of type int instead of an integer literal of type long" since technically they're both integer literals, but you get the point.
David J Evans
Greenhorn

Joined: Apr 28, 2006
Posts: 11
cheers ken, you're on the ball.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: converting from timestamp to date