- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我持久化一个 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中可以看到刚才放出的zone信息。我发现该应用程序何时在 heroku 上投入生产,服务器位于与用户不同的时区。一些发现者返回错误的结果。
这里来自 ledger.json:
"fields": [
{
"fieldName": "startDate",
"fieldType": "ZonedDateTime"
},
{
"fieldName": "endDate",
"fieldType": "ZonedDateTime"
},
我做错了什么吗?
最佳答案
MySQL 中的时间戳没有区域信息。因此,部署应用程序的服务器的区域信息很重要。保存在 db 中的时间将使用服务器的区域信息在 java 中创建为 dateTime。
对于从客户端传递到服务器的日期,还应包含区域信息,如“+04:00”。
对于 heroku,您应该找到一种方法来设置 java 应用程序的区域。您可以使用系统属性对其进行设置。也许 heroku 提供了一种方法来设置它。
关于mysql - jhipster 和 ZonedDateTime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46143383/
我创建了两个 ZonedDateTime 对象,我认为它们应该相等: public static void main(String[] args) { ZoneId zid = ZoneId.
假设我有一个 ZonedDateTime: ZonedDateTime zonedDateTime = ZonedDateTime.of(LocalDateTime.now(), ZoneI
给定以下单元测试: @Test public void zonedDateTimeCorrectlyRestoresItself() { // construct a new instance
我正在尝试将 ZonedDateTime 与以下代码进行比较: val now = ZonedDateTime.now() val query = for { x Timestamp.from(
我最近迁移到 Java 8,希望能更轻松地处理本地和分区时间。 但是,在我看来,在解析简单日期时,我遇到了一个简单的问题。 public static ZonedDateTime convertirA
您好,我已经搜索过类似的问题,但没有成功。我正在调用一个 ws,它将一个 token 发回给我,当它是有效的示例时: { "token": ..., "notBefore":"Thu 21
我有一个 ZonedDateTime 对象,我想根据给定的区域设置对其进行格式化。 IE。在美国,我希望格式为“M-dd-yy”,但在英国则应为“dd-M-yy”。 在给定的语言环境下执行此操作的最佳
在比较 ZonedDateTimes 时,使用 和 == 并不总是与使用 .isBefore、.isAfter 和 isEqual 相同,如下面的 Kotlin 示例所示: import java.
我有以下功能 public String getDateAndTimeInUserFormat(String value, DateTimeFormat inputFormat) { retu
我的时间以毫秒为单位,我需要将其转换为 ZonedDateTime 对象。 我有以下代码 long m = System.currentTimeMillis(); LocalDateTime d =
我尝试将字符串转换为 ZonedDateTime。这是我的代码: String startTime = "Wed Mar 21 2018 08:00:00 GMT 0330 (IRST)"; Stri
在比较 ZonedDateTimes 时,使用 和 == 并不总是与使用 .isBefore、.isAfter 和 isEqual 相同,如下面的 Kotlin 示例所示: import java.
我正在尝试获取存储为 UTC 的日期时间并将其转换为给定时区的日期时间。据我所知,ZonedDateTime 是正确的(“美国/芝加哥”比 UTC 晚 5 小时),但 DateTimeFormatte
我需要将字符串 2020-04-15T23:00:00+0000 转换为 ZonedDateTime。我尝试了以下方法,但没有成功: DateTimeFormatter formatter = Dat
如何将已设置的 ZonedDateTime 时间更改为“java.time.LocalTime.MIN”或“java.time.LocalTime.MAX”? ZonedDateTime date =
我正在尝试将字符串转换为 ZonedDateTime。 我尝试过以下操作: SimpleDateFormat zonedDateTimeFormat = new SimpleDateFormat("y
我目前正在研究日期在英国夏令时间之内和之外时的 ZonedDateTime 行为。 英国夏令时间从 3 月 25 日开始,增加一小时 (+1)。 我创建了几个 ZonedDateTime 实例(UTC
ZonedDateTime zdt3 = ZonedDateTime.parse("1999-09-09 09:09:09.999", DateTimeFormatter.of
我有一个返回年、月、日和小时的 DTO。因此将值从 DTO 传递到 ZonedDateTime.of 方法。此处,时间显示为太平洋标准时间上午 10 点。因此,尝试将其转换为 UTC。 当传递月份为
String ip="2011-05-01T06:47:35.422-05:00"; ZonedDateTime mzt = ZonedDateTime.parse(ip).toInstant().a
我是一名优秀的程序员,十分优秀!