且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java SimpleDateFormat:一小时错误

更新时间:2023-12-02 15:57:10

如果您在伦敦或巴黎,那么1970年1月1日的时区为GMT + 1。

If you are in London, or Paris, the timezone was GMT+1 on 1 Jan 1970.

原因@ARC在评论中解释说,英国在1968年2月18日至1971年10月31日期间使用GMT + 1或UTC + 1。

For reasons @ARC explains in the comments, the UK used GMT+1 or UTC+1 from 18 Feb 1968 to 31 Oct 1971


是可能为我转换一个长而没有任何时区干扰?

is it possible for me to convert a long without any timezones interfering?

将TimeZone设置为GMT。

Set the TimeZone to be GMT.

long millis = 2305293L;
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
System.out.println(sdf.format(new Date(millis)));

打印

00:38:25.293