jjzjj

zoneddatetime

全部标签

java - 在 ZonedDateTime 或 Instant 中将时分秒设置为 00

我有一个Utc格式的日期字符串-StringdateStr="2017-03-03T13:14:28.666Z";我想将其转换为ZonedDateTime中Java日期表示形式的以下格式。打印ZonedDateTime时应该显示StringdateStr="2017-03-03T00:00:00.000Z";我试过下面的代码-StringtimeZone="America/Los_Angeles";DateTimeFormatterdtf1=DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX");DateTimeFormatt

java - 如何从 org.joda.time.DateTime 转换为 java.time.ZonedDateTime

我有一个数据源,其中存储了joda时间DateTime对象。我需要将它们转换为javaZonedDateTime对象,同时保持原始时区。仅保留偏移量是不够的,因为某些DateTime对象表示日常重复性任务,并且这些任务必须在每个日期的特定时区的特定时间发生。因此,它们必须遵循指定的时区转换,例如夏令时和冬令时。我无法确定DateTime对象的最终用途,因此我需要保留所有对象的时区信息以确保安全。如何将org.joda.time.DateTime转换为java.time.ZonedDateTime?将全部ord.joda.time.DateTimeZone.getId()映射到可用的id

java - ZonedDateTime 和 Instant.toEpochMilli 的 MIN/MAX 值是多少?

我想使用可以在ZonedDateTime和Instant.toEpochMilli()之间转换的MIN/MAX时间值,用作过滤器/查询的标记值。我试过:OffsetDateTime.MIN.toInstant().toEpochMilli();OffsetDateTime.MAX.toInstant().toEpochMilli();但我得到了这个异常(exception):java.lang.ArithmeticException:longoverflowatjava.lang.Math.multiplyExact(Math.java:892)atjava.time.Instant.

java - ZonedDateTime 比较 : expected: [Etc/UTC] but was: [UTC]

我正在比较两个看似相等的日期,但它们包含不同名称的时区:一个是Etc/UTC,另一个是UTC。根据这个问题:IsthereadifferencebetweentheUTCandEtc/UTCtimezones?-这两个区域是相同的。但是我的测试失败了:importorg.junit.Test;importjava.sql.Timestamp;importjava.time.ZoneId;importjava.time.ZonedDateTime;importstaticorg.junit.Assert.assertEquals;publicclassTestZoneDateTime{@

java - 如何将 java.time.ZonedDateTime 转换为 XMLGregorianCalendar?

有什么简单的方法可以将java.time.ZonedDateTime转换为XMLGregorianCalendar?也许我需要一些中间步骤,例如将ZonedDateTime转换为java.util.Date,但这会使代码过于困惑。问题出现在JAX-WS网络服务中,那里的日期时间作为XMLGregorianCalendar传递。 最佳答案 目前我认为这是最直接的方法:ZonedDateTimenow=ZonedDateTime.now();GregorianCalendargregorianCalendar=GregorianCale

java - ZonedDateTime toString 与 ISO 8601 的兼容性

我试图确保在我的ZonedDateTime对象上调用toString()将符合ISO-8601格式。toString()方法的文档指出:...TheoutputiscompatiblewithISO-8601iftheoffsetandIDarethesame这是否意味着存在调用zdt.getOffset()将返回不同于zdt.getZone().getRules().getOffset(zdt.toInstant())?这似乎没有意义。有人可以提供一个偏移量和ID不相同的示例吗(即:toString()不符合ISO-8601的地方)以便我更好地理解中的描述文档。

java - 客户端发送的请求在语法上不正确 Java ZonedDateTime 后端

我希望得到一些帮助来调试这个问题。如果我将以下JSON发送到我的后端,它会正常工作:{"approvalRequired":false,"location":{"locationName":"+\/-5.00m(speed0.00mps\/course-1.00)@9\/16\/18,9:24:59PMPacificDaylightTime","longitude":-122.0312186,"latitude":37.332331410000002}}但是,如果我现在发送以下内容:{"approvalRequired":false,"scheduledStartTime":"2016

java - LocalDateTime , ZonedDateTime 和时间戳

我有一个SpringBoot应用程序。使用SpringInitializer、嵌入式Tomcat、Thymeleaf模板引擎,并打包为可执行JAR文件。我有一个具有2个属性(initDate、endDate)的域对象。我想创建2个转换器来处理mySQLDB@Convert(converter=LocalDateTimeAttributeConverter.class)privateLocalDateTimeinitDate;@Convert(converter=ZonedDateTimeAttributeConverter.class)privateZonedDateTimeendDa

java - 在实体类 java.time.ZonedDateTime 上找不到属性 null 以将构造函数参数绑定(bind)到

我有以下配置配置@Configuration@EnableMongoRepositories(basePackages=Constants.DATA_SCAN)@EnableMongoAuditing(auditorAwareRef="auditorAwareService")@Import(value=MongoAutoConfiguration.class)publicclassDatabaseConfiguration{@BeanpublicValidatingMongoEventListenervalidatingMongoEventListener(){returnnewVa

Java 8 - 将 LocalDate 转换为 ZonedDateTime

我是java.time包的新手。我有一个LocalDate2015-12-10。我需要将其转换为ZonedDateTime。时间应为00:00:00,区域为ZoneOffset.UTC。转换后ZonedDateTime应该是2015-12-10T00:00:00+02:00。我将LocalDate存储在一个名为startDate的变量中。我试过了:ZonedDateTime.ofInstant(Instant.from(startDate),ZoneOffset.UTC)但得到错误java.time.DateTimeException:UnabletoobtainInstantfrom