LocalDateTime格式化异常java.time.DateTimeException(Field DayOfYear cannot be printed as the value 296..

异常信息
Exception in thread “main” java.time.DateTimeException: Field DayOfYear cannot be printed as the value 296 exceeds the maximum print width of 2
at java.time.format.DateTimeFormatterBuilder N u m b e r P r i n t e r P a r s e r . f o r m a t ( D a t e T i m e F o r m a t t e r B u i l d e r . j a v a : 2559 ) a t j a v a . t i m e . f o r m a t . D a t e T i m e F o r m a t t e r B u i l d e r NumberPrinterParser.format(DateTimeFormatterBuilder.java:2559) at java.time.format.DateTimeFormatterBuilder NumberPrinterParser.format(DateTimeFormatterBuilder.java:2559)atjava.time.format.DateTimeFormatterBuilderCompositePrinterParser.format(DateTimeFormatterBuilder.java:2190)
at java.time.format.DateTimeFormatter.formatTo(DateTimeFormatter.java:1746)
at java.time.format.DateTimeFormatter.format(DateTimeFormatter.java:1720)
at com.tiefan.fsh.source.service.impl.MediaService.main(MediaService.java:97)

问题原因:日期时间格式书写错误
错误代码:
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(“yyyy-MM-DD hh:mm:ss”);
DD不应该使用大写;
**处理方式:**修改日期时间格式为标准格式;
正确代码:DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(“yyyy-MM-dd hh:mm:ss”);

扩展信息
标准时间格式字符:yyyy 表示年 必须小写
MM 表示月 必须大写,小写表示月份
dd 表示天 必须小写
HH/hh 表示小时 大小写均可
mm 表示分钟,必须小写,大写表示月份
ss 表示秒 必须小写 大写表示毫秒
SS 表示毫秒 必须大写 小写表示秒


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部