English 中文(简体)
当地时间(0年)的预测结果混乱?
原标题:DateTimeFormatter gets confusing results for LocalDateTime.withYear(0)?

Java version: 1.8.0_202
see code below:

DateTimeFormatter yy = DateTimeFormatter.ofPattern("yy");
DateTimeFormatter yyy = new DateTimeFormatterBuilder()
                .appendValueReduced(ChronoField.YEAR, 3, 3, 0)
                .toFormatter();
DateTimeFormatter yyyy = DateTimeFormatter.ofPattern("yyyy");

LocalDateTime now = LocalDateTime.now();
// set year is 0
LocalDateTime year0 = now.withYear(0);
System.out.println("year0: " + year0);                             // year0: 0000-01-10T09:53:03.551
System.out.println("year0.getYear(): 	" + year0.getYear());       // year0.getYear():    0
System.out.println("year0.format(yyyy): " + year0.format(yyyy));   // year0.format(yyyy): 0001
System.out.println("year0.format(yyy): 	" + year0.format(yyy));   // year0.format(yyy):  000
System.out.println("year0.format(yy): 	" + year0.format(yy));     // year0.format(yy):   01
System.out.println("============================================================");
// set year is 1
LocalDateTime year1 = now.withYear(1);
System.out.println("year1: " + year1);                             // year1: 0001-01-10T09:53:03.551
System.out.println("year1.getYear(): 	" + year1.getYear());       // year1.getYear():     1
System.out.println("year1.format(yyyy): " + year1.format(yyyy));   // year1.format(yyyy):  0001
System.out.println("year1.format(yyy): 	" + year1.format(yyy));   // year1.format(yyy):   001
System.out.println("year1.format(yy): 	" + year1.format(yy));     // year1.format(yy):    01

为什么year0.format(yyyyy)year0.format(yyy)0001或01,但year0.format(yyyyyy) 返回权000? 如何确定?

问题回答

为什么“yyy”给你造成不一致的结果,但。 The docs for AnnualFormatter states that y is for “year of life”, means shall never given 0 because no life (AD or BC) had a year 0. 根据这些缩略语,如果你想要没有时代就展示这一年的话,请重新寻找<代码>u而不是y

如果你想随同年显示这个时代的话,那么这个时代的编号为/code>。 i.e.yyyyyyyyy GG





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签