• Post Reply Bookmark Topic Watch Topic
  • New Topic

need help with LocalDateTime parse method  RSS feed

 
Rohit Gaikwad
Ranch Hand
Posts: 40
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the code



getting an error saying

Caused by: java.time.DateTimeException: Conflict found: Field MonthOfYear 1 differs from MonthOfYear 3 derived from 2011-01-25

But---------

the code is working fine when i am replacing the string --"2011-03-25 21:22:22" with the string "2011-01-25 21:22:22"
it mean when i am changing month to 01 its working fine but when its more then 1 its giving me an error .

need to know why is it so and where i am going wrong ..

Thanks in advance
 
Stephan van Hulst
Saloon Keeper
Posts: 7817
142
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"DD" means day of year. It tries to parse "25" as the 25th day of the year, which is in January. This conflicts with the 3rd month of the year, which is March.

Replace "DD" with "dd" and you should be golden.
 
Rohit Gaikwad
Ranch Hand
Posts: 40
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Stephan
I am one more question what is the difference in using YYYY or yyyy or uuuu as year string as even when i am changind yyyy to YYYY its giving me an Exception .
 
Les Morgan
Rancher
Posts: 768
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a link to the formatting for datetime: datetime formats
Rohit Gaikwad wrote:Thanks a lot Stephan I am one more question what is the difference in using YYYY or yyyy or uuuu as year string as even when i am changind yyyy to YYYY its giving me an Exception .
 
Roel De Nijs
Sheriff
Posts: 11338
177
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rohit Gaikwad wrote:I am one more question what is the difference in using YYYY or yyyy or uuuu as year string as even when i am changind yyyy to YYYY its giving me an Exception .

All these letters are explained in the API documentation of the DateTimeFormatter class:
  • u = year
  • y = year-of-era
  • Y = week-based-year


  • Regarding the week-based-year you'll probably find this explanation and this code snippet very usefulWithout line1 an exception is thrown at runtime.

    Hope it helps!
    Kind regards,
    Roel
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 7817
    142
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    December 26, 2 BC
    December 26 of the year -1
    Day 1 of week 1 of the year 0

    The year-of-era ("y") is what you're most accustomed to: it starts at January 1, 1 AD. The day before that is December 31, 1 BC.

    The proleptic year ("u") does the same for AD, except for BC it continues counting down: 0 for 1 BC, -1 for 2 BC, etc.

    The week-based-year ("Y") works the same as the proleptic year, except it doesn't start counting years at the 1st of January, but at the first weekday of the first week of the year.

    For example, if you start the week on Sunday (as the root locale does) then the week-based-year 2016 started on December 27, 2015.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!