File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Convert long to date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Convert long to date" Watch "Convert long to date" New topic

Convert long to date

Ken Shamrock
Ranch Hand

Joined: Jan 23, 2002
Posts: 139
I've this long number,long temp=1018021774496
but I can't feed it into Date.
Date date=new date(temp);
it always say:
E:\PROGRA~1\JRun\servers\default\demo-app\WEB-INF\classes>e:\jdk122\bin\javac -d
eprecation Integer literal out of range. Decimal int literals must be in t
he range -2147483648 to 2147483647.
long l=1018021079797;
So how can I convert that "long" number to xx/xx/xx xx:xx ? Thanks!

Thanks everyone who helped me
Brett Anthoine

Joined: Mar 12, 2002
Posts: 27
Hi Ken,
Maybe I'm missing the point, but I tried that code and it worked fine :

I think you just missed the "l" after the constant and the compiler used it as an int, trying a conversion but it was out of range.
But I'm far from being an expert, so if anyone can confirm ?

Brett Anthoine<br />"640k should be enough for anybody."
Ken Shamrock
Ranch Hand

Joined: Jan 23, 2002
Posts: 139
oh yeah, thanks, you are right, I missed out 'l', I seldom use long type, so don't know it need to add a 'l' at the end.
I agree. Here's the link:
subject: Convert long to date
It's not a secret anymore!