3

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?

Bohemian
  • 412,405
  • 93
  • 575
  • 722
user718146
  • 400
  • 1
  • 4
  • 16

3 Answers3

12

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.

Bohemian
  • 412,405
  • 93
  • 575
  • 722
1

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

gerrytan
  • 40,313
  • 9
  • 84
  • 99
0

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.

Adi
  • 2,364
  • 1
  • 17
  • 23