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

Categories

0 votes
635 views
in Technique[技术] by (71.8m points)

java - new Date(long) gives different results

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

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

1 Answer

0 votes
by (71.8m points)

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 :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...