Tag: datetime format

如何将LocalDateTime对象转换为包含时区的ISO字符串?

我试图将日期/时间字符串来回转换成LocalDateTime对象。 我正在使用ThreeTenBp作为日期/时间库。 字符串 – > LocalDateTime val actual = LocalDateTime.parse("2016-12-27T08:15:05.674+01:00", DateTimeFormatter.ISO_DATE_TIME) val expected = LocalDateTime.of(2016, 12, 27, 8, 15, 5, 674000000) assertThat(actual).isEqualTo(expected) // Successful LocalDateTime – >字符串 val dateTime = LocalDateTime.of(2016, 12, 27, 8, 15, 5, 674000000) val actual = dateTime.format(DateTimeFormatter.ISO_DATE_TIME) assertThat(actual).isEqualTo("2016-12-27T08:15:05.674+01:00") // Fails 出于某种原因,时区丢失: 预计:<… 6-12-27T08:15:05.674 [+01:00]“>但是:<… 6-12-27T08:15:05.674 []”> 预计:“2016-12-27T08:15:05.674 + 01:00” 实际情况:“2016-12-27T08:15:05.674”

如何解析Kotlin中RestController的LocalDateTime

我试图用kotlin为我的应用程序实现一个控制器。 但是,当我提出get请求时解析日期时间格式时出现错误。 @RestController @RequestMapping("/api/records") class RecordController(val recordService: RecordService) { @GetMapping("details") fun getRecordDetail( @RequestParam recordId: Int, @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) dateTime: LocalDateTime): RecordDto { return recordService.getRecordDetails(recordId, dateTime) } } 错误是 Failed to convert value of type 'java.lang.String' to required type 'java.time.LocalDateTime'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@org.springframework.web.bind.annotation.RequestParam […]