jjzjj

zoneddatetime

全部标签

java - 为什么 Java 8 ZonedDateTime 认为 24​​ :01 is a valid time string representation?

我需要获取两个ZonedDateTime实例,分别代表本周的开始和结束。ZonedDateTimecurrentDateTime=ZonedDateTime.now();ZonedDateTimestartOfThisWeek=currentDateTime.with(DayOfWeek.MONDAY).truncatedTo(ChronoUnit.DAYS).plusMinutes(1);ZonedDateTimeendOfThisWeek=startOfThisWeek.plusDays(6);DateTimeFormatterdf=DateTimeFormatter.ofPatt

java - ZonedDateTime 与 MongoDB

尝试将ZonedDateTime与MongoDB一起使用。我可以将ZonedDateTime保存在MongoDB中,但是当我查看记录时,里面有很多不必要的东西:>"timestamp":{>"dateTime":ISODate("2016-12-13T13:45:53.991Z"),>"offset":{>"_id":"-05:00",>"totalSeconds":-18000>},>"zone":{>"_class":"java.time.ZoneRegion",>"_id":"America/New_York",>"rules":{>"standardTransitions":[

java - ZonedDateTime 与 MongoDB

尝试将ZonedDateTime与MongoDB一起使用。我可以将ZonedDateTime保存在MongoDB中,但是当我查看记录时,里面有很多不必要的东西:>"timestamp":{>"dateTime":ISODate("2016-12-13T13:45:53.991Z"),>"offset":{>"_id":"-05:00",>"totalSeconds":-18000>},>"zone":{>"_class":"java.time.ZoneRegion",>"_id":"America/New_York",>"rules":{>"standardTransitions":[

java - 如何将 ZonedDateTime 格式化为字符串?

我想将ZonedDateTime转换为("dd/MM/yyyy-hh:mm")格式的String.我知道这在Joda-Time其他类型中是可能的,只需使用他们的toString("dd/MM/yyyy-hh:mm")....但这不适用于ZonedDateTime.toString().如何将ZonedDateTime格式化为String?编辑:我尝试在另一个时区打印时间,结果似乎总是一样:ZonedDateTimedate=ZonedDateTime.now();ZoneIdla=ZoneId.of("America/Los_Angeles");ZonedDateTimedate2=d

Java 8 - ZonedDateTime 的 DateTimeFormatter 和 ISO_INSTANT 问题

所以我希望这段代码可以在新的Java8日期/时间包下工作,因为它所做的只是使用相同的内置DateTimeFormatter实例(ISO_INSTANT)将给定的ZonedDateTime转换为字符串并返回:ZonedDateTimenow=ZonedDateTime.now();System.out.println(ZonedDateTime.parse(now.format(DateTimeFormatter.ISO_INSTANT),DateTimeFormatter.ISO_INSTANT));但显然不是:Exceptioninthread"main"java.time.form

Java 8 : How to create a ZonedDateTime from an Epoch value?

Java8的LocalDateTime有一个ofEpochSecond方法。不幸的是,ZonedDateTime中没有这样的方法。现在,我有一个Epoch值和一个明确的ZoneId给出。如何从中获得ZonedDateTime? 最佳答案 您应该能够通过Instant类来做到这一点,它可以表示给定纪元时间的时刻。如果你有纪元秒,你可以通过类似的东西创建一些东西Instanti=Instant.ofEpochSecond(t);ZonedDateTimez=ZonedDateTime.ofInstant(i,zoneId);

Java 8 日期时间 : get start of day from ZonedDateTime

这些有什么区别吗:zonedDateTime.truncatedTo(ChronoUnit.DAYS);zonedDateTime.toLocalDate().atStartOfDay(zonedDateTime.getZone());有什么理由偏爱一个而不是另一个?谢谢 最佳答案 为了更正而更新:在大多数情况下是一样的,当从冬季时间切换到夏季时间时,请参见以下巴西示例:ZonedDateTimezdt=ZonedDateTime.of(2015,10,18,0,30,0,0,ZoneId.of("America/Sao_Paulo

spring - 使用 Spring Boot >= 2.0.1.RELEASE 将 ZonedDateTime 保存到 MongoDB 时出现 CodecConfigurationException

我能够通过对AccessingDatawithMongoDB的官方SpringBoot指南进行最小修改来重现我的问题,见https://github.com/thokrae/spring-data-mongo-zoneddatetime.将java.time.ZonedDateTime字段添加到Customer类后,运行指南中的示例代码失败并出现CodecConfigurationException:客户.java:publicStringlastName;publicZonedDateTimecreated;publicCustomer(){输出:...Causedby:org.bs

java - Jackson 在 Spring Boot 中错误地序列化了 ZonedDateTime

我有一个带有SpringBoot和Jetty的简单应用程序。我有一个简单的Controller,它返回一个具有Java8ZonedDateTime的对象:publicclassDevice{//...privateZonedDateTimelastUpdated;publicDevice(Stringid,ZonedDateTimelastUpdated,intcourse,doublelatitude,doublelongitude){//...this.lastUpdated=lastUpdated;//...}publicZonedDateTimegetLastUpdated()

java - ZonedDateTime 和 OffsetDateTime 有什么区别?

我已经阅读了文档,但我仍然不知道什么时候应该使用其中一个:OffsetDateTimeZonedDateTime根据文档OffsetDateTime应该在将日期写入数据库时​​使用,但我不明白为什么。 最佳答案 Q:What'sthedifferencebetweenjava8ZonedDateTimeandOffsetDateTime?javadocs是这样说的:"OffsetDateTime,ZonedDateTimeandInstantallstoreaninstantonthetime-linetonanosecondpre