Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

java.sql.Date - setting a future date?  RSS feed

 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to set a java.sql.Date to represent 40 weeks into the future, but my code doesn't work...



The output is:

millisNow: 1194011136901 <-- prob ok
millisPurchased: -1577803776 <-- why a negative??
expiryDate: 2007-10-15 08:28:53.125 <-- this is 2.5 weeks ago, not 40 weeks into future!

I'm sure it's something obvious?...
 
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try a long!

long millisPurchased = 1000 * 60 * 60 * 24 * 7 * 40L;

Herman
 
Sheriff
Posts: 21458
96
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To be honest, you should use a Calendar instead. What if there is daylight savings time, or something like that?

 
James Hodgkiss
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Calendar it is - cheers.

Btw, it's Calendar.getInstance() not Calendar.instance(). Anyone knows that! :roll:
 
Rob Spoor
Sheriff
Posts: 21458
96
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As do I - if I'm not writing code this quickly

When I reply quickly, I don't really check my code all the time. Everybody gets the point I'm trying to make, and with a quick look at the API everybody can fix these little errors I make.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!