获取日期可以追溯到一天 [英] Getting the date goes back one day

查看:64
本文介绍了获取日期可以追溯到一天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有字段

public class MovieReleaseDateEntity {
     @Basic
     @Column(name = "release_date")
     @Temporal(TemporalType.DATE)
     private Date date;
}

我将日期保存在数据库中

I save the date in the database

https://zapodaj.net/14dfcfb70926a.png.html

我从数据库中下载了它

"date": "2017-12-06T23:00:00.000+0000"

日期被撤消一天.为什么?

The date is withdrawn by one day. Why?

推荐答案

tl; dr

这些都代表时间轴上的同一点,同时是同一时刻:

tl;dr

These all represent the very same point on the timeline, the very same simultaneous moment:

  • 2017-12-06T23:00:00.000 + 0000
  • 2017-12-07T00:00:00.000 + 01:00
  • 2017-12-07T04:30:00.000 + 05:30

欧洲/华沙时区当前比一小时href ="https://en.wikipedia.org/wiki/Coordinated_Universal_Time" rel ="nofollow noreferrer"> UTC .

"2017-12-06T23:00:00.000 + 0000"

"2017-12-06T23:00:00.000+0000"

您的字符串代表UTC的时刻.请注意 +0000 ,缩写为 +00:00 ,这表示与UTC的零小时零分钟的偏移量.所以它在世界标准时间.

Your string represents a moment in UTC. Note the +0000, an abbreviation of +00:00, which means an offset of zero hours and zero minutes from UTC. So it is at UTC.

从波兰墙上的时钟镜头看到的那一刻,是下一个约会的早晨00:00.那是波兰新的一天的第一刻.

That same moment as seen thorough the lens of a clock on the wall on Poland is 00:00 on the morning of the next date. That is the first moment of the new day in Poland.

"2017-12-07T00:00:00.000 + 01:00"

"2017-12-07T00:00:00.000+01:00"

同一时刻稍后在印度的墙上时钟上,人们比UTC提前了五个半小时.

That same moment is later on a wall-clock in India where the people live five and a half hours ahead of UTC.

"2017-12-07T04:30:00.000 + 05:30"

"2017-12-07T04:30:00.000+05:30"

如果波兰的一名失眠者在北美西海岸给他们的朋友打电话,他们可能会在早些时候的下午3点下午抓住他们的朋友继续工作.墙上的时钟比世界协调时间晚八小时.

If an insomniac in Poland called their friend on the west coast of North America, they might catch their friend still on the job in mid-afternoon at 3 PM on the earlier date. There the clock on the wall is eight hours behind UTC.

"2017-12-06T15:00:00.000-08:00"

"2017-12-06T15:00:00.000-08:00"

将输入字符串解析为 OffsetDateTime 对象.要查看其他时区的同一时刻,请添加 ZoneId 以获取 ZonedDateTime .搜索堆栈溢出以获取详细信息,因为已经对此进行了很多次讨论.

Parse your input string as an OffsetDateTime object. To view the same moment in other time zones, adding a ZoneId to get a ZonedDateTime. Search Stack Overflow for details as this has been covered many many times already.

避免麻烦的,有缺陷的旧日期时间类,例如 Date .仅使用其替代品,即现代业界领先的java.time类.

Avoid the troublesome flawed old date-time classes such as Date. Use only their replacements, the modern industry-leading java.time classes.

这篇关于获取日期可以追溯到一天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆