【发布时间】:2020-01-21 16:54:55
【问题描述】:
我的代码使用myTime.toString 将 LocalDateTime 保存为字符串。它在使用 Spring 转换器从 String 转换为 LocalDateTime 时被读回。任何地方都没有格式化,设置为使用系统默认值。
在一个环境中读取它,因为默认格式似乎不正确 (2019-03-01T11:51:07.017)
Caused by: org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.time.LocalDateTime] for value '2020-01-13T07:00'; nested exception is java.time.format.DateTimeParseException: Text '2020-01-13T07:00' could not be parsed at index 16
此属性是否有任何系统范围的配置,或者我应该在任何地方显式格式化?
【问题讨论】:
-
您可以在某处存储
DateTimeFormatter的实例并继续使用它。 -
您是否在某处指定了明确的格式?
LocalDateTime类可以毫无错误地解析这两个输入(2019-03-01T11:51:07.017和2020-01-13T07:00)。 -
无任何格式。当我执行 toString 时,是否有一个环境属性说明默认值是什么?
-
请检查docs.oracle.com/javase/8/docs/api/java/time/… 默认toString格式
标签: java spring date formatting environment