【问题标题】:jhipster and ZonedDateTimejhipster 和 ZonedDateTime
【发布时间】:2018-02-18 23:14:21
【问题描述】:

当我坚持一个 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 Workbemnch 中:

 '6', '2017-09-01 00:00:00', '2017-09-30 23:59:59', 'OPEN', NULL, '1', '3'

,在Workbench中可以看到刚刚发布的区域信息。 我发现该应用程序何时在 heroku 上投入生产,其中服务器与用户位于另一个时区。一些发现者返回错误的结果。

来自 ledger.json:

"fields": [
    {
        "fieldName": "startDate",
        "fieldType": "ZonedDateTime"
    },
    {
        "fieldName": "endDate",
        "fieldType": "ZonedDateTime"
    },

我做错了吗?

【问题讨论】:

    标签: mysql jhipster zoneddatetime


    【解决方案1】:

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

    对于从客户端传递到服务器的日期,还应包含区域信息,例如“+04:00”。

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

    【讨论】:

      猜你喜欢
      • 2019-03-12
      • 1970-01-01
      • 2017-10-15
      • 1970-01-01
      • 2020-05-23
      • 2018-11-26
      • 1970-01-01
      • 1970-01-01
      • 2019-01-21
      相关资源
      最近更新 更多