# Help for future date？

David Song

Greenhorn

Posts: 8

posted 6 years ago

- 0

The numbers you are doing the math with (150 * 1000 * 60 * 60 * 24) are all integers, which means the result will be an integer. Integers have a max value which this calculation exceeds, so it wraps around and becomes negative - and probably comes back up to being just a few hours ahead instead of a lot of days ahead. Since the result you need has to be a long, you should use longs in the calculation - at least one of the constants should be a long so the rest of them can be widened:

Or make it a little more readable:

Also, take a look at the Calendar class, it has methods built in for doing date math, which you should prefer to use.

Or make it a little more readable:

Also, take a look at the Calendar class, it has methods built in for doing date math, which you should prefer to use.

Steve

posted 6 years ago

Exactly. Calendar will take daylight savings into account. You know, those two days in a year that actually don't have 24 hours.

- 0

Steve Luke wrote:Also, take a look at the Calendar class, it has methods built in for doing date math, which you should prefer to use.

Exactly. Calendar will take daylight savings into account. You know, those two days in a year that actually don't have 24 hours.

SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6

How To Ask Questions How To Answer Questions

I agree. Here's the link: http://aspose.com/file-tools |