【发布时间】:2021-08-27 06:50:03
【问题描述】:
我正在尝试转换时区,但它从 java 函数中增加了一天。
"" deActivationDate=2021-06-25T23:59:59.000+0000"";
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
try {
Date date =formatter.parse(deActivationDate);
deActivationDate=formatter.format(date);
LOGGER.info("time format printing 1" +deActivationDate);//2021-06-26T04:29:59.000+0430
deActivationDate = deActivationDate.substring(0, deActivationDate.length()-2)+":30";
LOGGER.info("time format printing 2" +deActivationDate);//2021-06-26T04:29:59.000+04:30""
在上面的停用日期是 25,当我提供输入但在格式化程序解析方法之后,它转换为 26,为什么有一天操作系统会添加如何避免它。
【问题讨论】:
-
上述日期为UTC +0:0时区,转换后的日期为UTC +4:30,正确。有什么问题?
-
顺便说一句,你为什么不切换到“新”的 java.time api 来让事情变得更容易?
-
如果格林威治时间是凌晨 12 点 (UTC +00:00),那么在您的手表中,时间将为凌晨 4:30,因为您距离时区中心 4.5 小时
-
在解析日期之前,您可能想在日期格式化程序中添加特定时区
formatter.setTimeZone(TimeZone.getTimeZone("UTC"))
标签: java timezone java-7 datetime-format