[英]Java - date, format, time zones and Spring Boot defaults
I have simple Java object with a date field: 我有一个带有日期字段的简单Java对象:
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
private Date date;
When I investigate the date with debugger I see: 当我使用调试器调查日期时,我看到:
Wed Jun 14 00:00:00 BST 2017
But once I return it with Spring boot
controller
I get: 但是一旦我用Spring boot
controller
返回它,我就会得到:
"date": "2017-06-13 23:00:00"
BST
? 为什么Java将日期视为BST
? Date
class contain time-zone information or just plain timestamp in long format? Java Date
类包含时区信息还是长格式的纯时间戳? Spring boot
using UTC
format by default while serialising DTOs to JSON? 在将DTO序列化为JSON时, Spring boot
默认情况下是否使用UTC
格式Spring boot
? java.util.Date
has no timezone information (only the long
timestamp), but it uses the system's default timezone in the toString()
method - you can find more info about this here (as already suggested in the comments). java.util.Date
没有时区信息(只有long
时间戳),但是它在toString()
方法中使用系统的默认时区-您可以在此处找到有关此信息的更多信息(如注释中所建议)。
Just check the value of TimeZone.getDefault()
. 只需检查TimeZone.getDefault()
的值即可。 It'll probably be Europe/London
- as London in now in summer time, the short name (used by Date.toString()
) of this timezone is BST
. 可能是Europe/London
-在夏季,现在是伦敦,该时区的简称(由Date.toString()
)为BST
。
As your output suggests, Spring is probably using UTC
(as 2017-06-13 23:00:00
in UTC
is 2017-06-14 00:00:00
in BST
). 作为输出表明,春天是可能使用UTC
(如2017-06-13 23:00:00
在UTC
是2017-06-14 00:00:00
在BST
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.