首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jhipster和ZonedDateTime

jhipster和ZonedDateTime
EN

Stack Overflow用户
提问于 2017-09-11 01:11:47
回答 1查看 737关注 0票数 1

当我持久化一个ZonedDateTime时,区域信息就被释放了。

代码语言:javascript
复制
    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);

日志的输出如下:

代码语言:javascript
复制
  firstMomentInMonth =  2017-09-01T00:00-04:00[America/Santo_Domingo]
  lastMomentInMonth = 2017-09-30T23:59:59.999999999-04:00[America/Santo_Domingo]

在MySql工作区中:

代码语言:javascript
复制
 '6', '2017-09-01 00:00:00', '2017-09-30 23:59:59', 'OPEN', NULL, '1', '3'

,在工作台中,您可以看到区域信息刚刚释放。我发现这个应用程序是什么时候在heroku上投入生产的,在heroku上,服务器与用户位于另一个时区。一些查找器返回的结果是错误的。

来自ledger.json的以下内容:

代码语言:javascript
复制
"fields": [
    {
        "fieldName": "startDate",
        "fieldType": "ZonedDateTime"
    },
    {
        "fieldName": "endDate",
        "fieldType": "ZonedDateTime"
    },

我做错了什么吗?

EN

回答 1

Stack Overflow用户

发布于 2018-08-13 18:11:54

MySQL中的时间戳没有区域信息。因此,部署应用程序的服务器的区域信息很重要。保存在数据库中的时间将使用服务器的区域信息创建到java中的dateTime中。

对于从客户端传递到服务器的日期,也应该包含区域信息,如'+04:00‘。

对于heroku,您应该找到一种方法来设置java应用程序的区域。您可以使用系统属性来设置它。也许heroku提供了一种方法来设置它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46143383

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档