LocalDateTime
是偏移量/时区不可知类。你需要OffsetDateTime
上课。
字符串-> OffsetDateTime
val actual = OffsetDateTime.parse("2016-12-27T08:15:05.674+01:00", DateTimeFormatter.ISO_DATE_TIME) val expected = OffsetDateTime.of(2016, 12, 27, 8, 15, 5, 674000000, ZoneOffset.of("+01:00")) assertThat(actual).isEqualTo(expected)
OffsetDateTime->字符串
val dateTime = OffsetDateTime.of(2016, 12, 27, 8, 15, 5, 674000000, ZoneOffset.of("+01:00")) val actual = dateTime.format(DateTimeFormatter.ISO_DATE_TIME) assertThat(actual).isEqualTo("2016-12-27T08:15:05.674+01:00")