• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java.util.Date setTime() API gives error

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Celina Joseph
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic