Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

When I run this code:

System.out.println( "XXX date=" + new Date( 1311781583373L ) );

I get this result in Eclipse's JUnit runner:

XXX date=Wed Jul 27 16:46:23 GMT+01:00 2011

and this result in Maven from the command line:

XXX date=Wed Jul 27 17:46:23 CEST 2011

As you can see, the hour is different.

(same computer, same Java version, maybe 30s apart). Why?

[EDIT] Also the time zone is different. Why is Java using CEST when it's started from Maven and GMT+01:00 when started from Eclipse?

Or to put it another way: How can I force Java to use either?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
605 views
Welcome To Ask or Share your Answers For Others

1 Answer

Looks like Maven and Eclipse have picked up different default time zones, that's all.

Don't forget that Date.toString() uses the default time zone. I would personally prefer to use Joda Time and probably log the UTC value instead of a local time :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...