我想将日期转换为不同格式的字符串,但出现以下错误,
DateTimeException-Field DayOfYear cannot be printed as the value 234 exceeds the maximum print width of 2
Run Code Online (Sandbox Code Playgroud)
下面是不同的格式,
"MMDDYY"
"DD_MM_YY"
"YYYYMMDD"
"MMDD"
"DD-MM-YY"
Run Code Online (Sandbox Code Playgroud)
下面是我的代码,
LocalDate localDate = LocalDate.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("DD-MM-YY");
String formattToString = localDate.format(formatter);
Run Code Online (Sandbox Code Playgroud)
我在这里错过了什么吗?
这是代码:
LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(1451438792953L), ZoneId.of("UTC"));
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("YYYY-MM-dd'T'HH:mm:ss.SSS'Z'");
String output = dateTimeFormatter.format(localDateTime);
Run Code Online (Sandbox Code Playgroud)
这是值localDateTime:
2015-12-30T01:26:32.953
Run Code Online (Sandbox Code Playgroud)
这是值output:
2016-12-30T01:26:32.953Z
Run Code Online (Sandbox Code Playgroud)
为什么要增加一年?
其中java.time.temporal.WeekFields有几种方法,有时会newYearWeek增加年数1。为什么?
这是一个奇怪的错误。