开发者

Java SimpleDateFormat and 19700101 conversion problem

i have a little problem with date conversion in java. When i put 19700101 to SimpleDateFormat and then call getTime i got -3600000. I write test:

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
Date date = dateFormat.parse("19700101");
System.out.println(date.getTim开发者_如何学编程e());
System.out.println(dateFormat.format(new Date(0)));
System.out.println((new Date(0)).getTime());

Result should be:

0
19700101
0

but i got

-3600000
19700101
0

My question is why SimpleDateFormat return -3600000 (20Nov1969)? Where I can find information about formatting and conversion bugs?


Which time zone were you using? My guess is you were using GMT+1. Set the timezone to "GMT" and you should get the expected result.

You are using a default timezone like CEST (GMT+1). When it was 1970/01/01 00:00:00.000 CEST was 1969/12/31 23:00:00.000 GMT which is -1h from 1970/01/01 or -3600000 ms.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜