• Post Reply Bookmark Topic Watch Topic
  • New Topic

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: 21255
87
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: 21255
87
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!