当我持久化一个ZonedDateTime时,区域信息就被释放了。
ZonedDateTime now = ZonedDateTime.now(ZoneId.of("America/Santo_Domingo"));
ZonedDateTime firstMomentInMonth = now.withDayOfMonth(1).truncatedTo(ChronoUnit.DAYS);
ZonedDateTime lastMomentInMonth = now.withDayOfMonth(now.toLocalDate().lengthOfMonth()).truncatedTo(ChronoUnit.DAYS).with(LocalTime.of(23, 59, 59, 999999999));
log.debug("firstMomentInMonth = {}", firstMomentInMonth);
log.debug("lastMomentInMonth = {}", lastMomentInMonth);
ledger = new Ledger();
ledger.setStartDate(firstMomentInMonth);
ledger.setEndDate(lastMomentInMonth);
return ledgerRepository.save(ledger);日志的输出如下:
firstMomentInMonth = 2017-09-01T00:00-04:00[America/Santo_Domingo]
lastMomentInMonth = 2017-09-30T23:59:59.999999999-04:00[America/Santo_Domingo]在MySql工作区中:
'6', '2017-09-01 00:00:00', '2017-09-30 23:59:59', 'OPEN', NULL, '1', '3',在工作台中,您可以看到区域信息刚刚释放。我发现这个应用程序是什么时候在heroku上投入生产的,在heroku上,服务器与用户位于另一个时区。一些查找器返回的结果是错误的。
来自ledger.json的以下内容:
"fields": [
{
"fieldName": "startDate",
"fieldType": "ZonedDateTime"
},
{
"fieldName": "endDate",
"fieldType": "ZonedDateTime"
},我做错了什么吗?
发布于 2018-08-13 18:11:54
MySQL中的时间戳没有区域信息。因此,部署应用程序的服务器的区域信息很重要。保存在数据库中的时间将使用服务器的区域信息创建到java中的dateTime中。
对于从客户端传递到服务器的日期,也应该包含区域信息,如'+04:00‘。
对于heroku,您应该找到一种方法来设置java应用程序的区域。您可以使用系统属性来设置它。也许heroku提供了一种方法来设置它。
https://stackoverflow.com/questions/46143383
复制相似问题