DateTime dt = new DateTime("2014-09-15T21:20:14");
System.out.println(dt);
System.out.println(dt.plusMillis(581042272).toDateTime().toLocalDateTime().toDateTime(DateTimeZone.forID("GMT")));
dt 中的时间是 UTC 时间,我想将 dt 中的时间加上毫秒设置为 GMT?但是,时间仍显示为 UTC(比 GMT 晚 1 小时)。我怎样才能将它设置为提前一小时?
2014-09-15T21:20:14.000+01:00
2014-09-22T14:44:16.272Z
我知道时间正好晚了一小时,因为我是在 15:44:16 GMT 提出此请求的
Your DateTime
实际上是not以 UTC 表示 - 位于系统默认时区。要修复此问题,您只需告诉它您传入的值采用 UTC 格式:
DateTime dt = new DateTime("2014-09-15T21:20:14", DateTimeZone.UTC);
System.out.println(dt);
DateTime other = dt.plusMillis(581042272);
System.out.println(other);
Output:
2014-09-15T21:20:14.000Z
2014-09-22T14:44:16.272Z
另请注意,您无法在格林尼治标准时间 15:44:16 提出请求,因为这种情况尚未发生。在我写这篇文章时,英国夏令时间为 16:05,因此格林尼治标准时间为 15:05。重要的是要了解英国的时区不是“GMT”——这只是我们不遵守夏令时时区的一部分。
如果您想转换为英国时区,您需要:
DateTime other = dt.plusMillis(581042272)
.withZone(DateTimeZone.forID("Europe/London"));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)