Question

I found a bizarre phenomenon in my java program at runtime, just look at my code:

System.out.println(" date " + new Date(1359931355141L).toGMTString() );

the output by this statement was "date 3 Feb 2013 22:42:35 GMT", and

System.out.println(" date " + new Date(1359931355141L).getDate() );

the output by this was "date 4" , see, why not 3 here ???

I could not figure out what's wrong with my program; I am doubting whether my JVM ran into bugs.
Guys, would you like to have a test on your JVM for this two statements?

Was it helpful?

Solution

Because you live east of central Europe (in a timezone that is at least GMT+1.5Hr).

getDate() (which is deprecated btw) returns the day of the month, and it's returning 4 (instead of 3) because in your timezone, that epoch time is already into the next day, whereas in England (GMT) it's still day 3 of the month.

OTHER TIPS

What's your locale? If it's 3 Feb 2013 22:42:35 GMT but your locale is GMT+10 then your local date will be 4. Nothing bizzare at all, this is the expected behavior

Well. that depends on what your current locale is. GMT will give you time if GMT timezone. getDate will give you time of your locale.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top