- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
给定一个由时间戳(例如“2016-06-07 08-01-55”)和特定 ZoneId(“欧洲/柏林”)组成的 Instant,此代码的预期结果是什么?
ZonedDateTime.ofInstant(timestamp.toInstant, zoneId)
会不会
'2016-06-07 08-01-55 +02:00' (time doesn't change, but ZoneId is changed)
或
'2016-06-07 10-01-55 +02:00' (time & ZoneId are changed)
我问这个问题是因为我在不同的环境中看到了这两种行为。
最佳答案
假设您正确设置了每个参数,输出是确定性的。使用您的数据:
LocalDateTime datetime = LocalDateTime.of(2016, 6, 7, 8, 1, 55);
ZonedDateTime zdt = datetime.atZone(ZoneId.of("Europe/Berlin"));
Instant instant = zdt.toInstant();
Timestamp ts = Timestamp.from(instant); //The timestamp you describe in your question
ZonedDateTime result = ZonedDateTime.ofInstant(ts.toInstant(), ZoneId.of("Europe/Berlin"));
System.out.println(result); //WILL ALWAYS PRINTS: 2016-06-07T08:01:55+02:00[Europe/Berlin]
关于java - 从 Instant 和 ZoneId 形成 ZonedDateTime 时的预期行为是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37675983/
要获得一个 ZoneId 它是这样的: ZoneId.of("America/Sao_Paulo"); 或 ZoneId.of(ZoneId.SHORT_IDS.get("BET")); 为什么不存在
ZoneId.of("Australia/ACT").getRules().getOffset(LocalDateTime.of(2019, 03, 31, 13, 0, 0, 0)) 返回 +11:
通过 of("...") 方法获取 ZoneId 需要一个具有特定 ID 的字符串。可以使用 ZoneId.getAvailableZoneIds() 检索可用的 ID。这将返回(至少在我的系统和 J
本文整理了Java中java.time.ZoneId.from()方法的一些代码示例,展示了ZoneId.from()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Mav
本文整理了Java中java.time.ZoneId.of()方法的一些代码示例,展示了ZoneId.of()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平
我有一个时区列表,我希望用户从中进行选择。所以,我认为我可以调用 java.time.ZoneId.getAvailableZoneIds() 并对它们使用方法 getDisplayName。这会导致
我现在正在巴黎运行这段代码,时间是 12:40,其中 ECT = ECT - Europe/Paris LocalDateTime creationDateTime = LocalDateTime.n
本文整理了Java中java.time.ZoneId.normalized()方法的一些代码示例,展示了ZoneId.normalized()的具体用法。这些代码示例主要来源于Github/Stack
本文整理了Java中java.time.ZoneId.ofOffset()方法的一些代码示例,展示了ZoneId.ofOffset()的具体用法。这些代码示例主要来源于Github/Stackover
本文整理了Java中java.time.ZoneId.getDisplayName()方法的一些代码示例,展示了ZoneId.getDisplayName()的具体用法。这些代码示例主要来源于Gith
本文整理了Java中java.time.ZoneId.hashCode()方法的一些代码示例,展示了ZoneId.hashCode()的具体用法。这些代码示例主要来源于Github/Stackover
本文整理了Java中java.time.ZoneId.toString()方法的一些代码示例,展示了ZoneId.toString()的具体用法。这些代码示例主要来源于Github/Stackover
本文整理了Java中java.time.ZoneId.equals()方法的一些代码示例,展示了ZoneId.equals()的具体用法。这些代码示例主要来源于Github/Stackoverflow
本文整理了Java中java.time.ZoneId.getAvailableZoneIds()方法的一些代码示例,展示了ZoneId.getAvailableZoneIds()的具体用法。这些代码示
本文整理了Java中java.time.ZoneId.systemDefault()方法的一些代码示例,展示了ZoneId.systemDefault()的具体用法。这些代码示例主要来源于Github
本文整理了Java中java.time.ZoneId.getRules()方法的一些代码示例,展示了ZoneId.getRules()的具体用法。这些代码示例主要来源于Github/Stackover
本文整理了Java中java.time.ZoneId.getId()方法的一些代码示例,展示了ZoneId.getId()的具体用法。这些代码示例主要来源于Github/Stackoverflow/M
本文整理了Java中org.threeten.bp.ZoneId.of()方法的一些代码示例,展示了ZoneId.of()的具体用法。这些代码示例主要来源于Github/Stackoverflow/M
我有一些代码可以从记录中读取短时区 ID 并将其传递给以下内容: ZoneId.of(ZoneId.SHORT_IDS.get(place.getTz())) 我无法控制使用什么时区 ID,但我的印象
我正在尝试使用 Java 的 ZoneId 和 ZoneOffsetTransitionRule 为 iCalendar VTIMEZONE 对象建模。 我的 VTIMEZONE 对象看起来像 BEG
我是一名优秀的程序员,十分优秀!