aspose file tools*
The moose likes Java in General and the fly likes java.util.Date setTime() API gives error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "java.util.Date setTime() API gives error" Watch "java.util.Date setTime() API gives error" New topic
Author

java.util.Date setTime() API gives error

Celina Joseph
Greenhorn

Joined: Aug 23, 2001
Posts: 24
Hi,
I am passing a long value to the java.util.Date API -
setTime()
It gives me error - "integer number too large."
The API signature is -
public void setTime(long time)
It is expecting a long, but I do not understand on passing a valid long value, it gives me error saying the integer value is too large.
Please let me know what is happening here.
Thanks
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Celina,
You're gonna have to show us some code or at least the exception's stack trace before we can help you here.
Michael Morris


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Celina Joseph
Greenhorn

Joined: Aug 23, 2001
Posts: 24
The code sample is -
Date dtt = new Date();
dtt.setTime(10480291150);
And the error that I got is -
C:\perso\SampleCode>javac TestUTCDate.java
TestUTCDate.java:14: integer number too large: 10480291150
dtt.setTime(10480291150);
^
1 error
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Celina,
Oh! A compiler error!. Just add the letter L after your value: date.setTime(10480291150L) and it should work. All integral values are interpreted by the compiler as int unless you specify otherwise.
Michael Morris
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: java.util.Date setTime() API gives error