相关文章推荐
谦和的电池  ·  Spring Cloud Stream ...·  9 月前    · 
重情义的青椒  ·  Android ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

To write test I need to set LocalDateTime to 0000-00-00 00:00:00 . When I try to set it using formatter:

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime.parse("0000-00-00 00:00:00", formatter)

it throws an exception:

java.time.format.DateTimeParseException: Text '0000-00-00 00:00:00' could not be parsed: Invalid value for YearOfEra (valid values 1 - 999999999/1000000000): 0

How can I do this?

  • There's no day 0 in any month. Days always starts in 1
  • There's no month 0 in any year. Months always starts in 1
  • There's no year 0 in the Gregorian calendar. That's the error you're getting (Invalid value for YearOfEra). You should set a year greater than 0
  • Two thirds correct. There is a year 0 in the proleptic Gregorian calendar. LocalDateTIme and the other classes from java.time use this calendar. Only there is no year 0 in the default era (common era or anno dominum). – Ole V.V. Jan 18, 2020 at 11:59

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.