Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

need help with LocalDateTime parse method

 
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
 
Saloon Keeper
Posts: 12279
259
  • 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 .
 
Rancher
Posts: 904
22
Netbeans IDE Oracle MySQL Database Tomcat Server C++ Java
  • 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 .

 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • 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: 12279
    259
    • 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.
     
    Consider Paul's rocket mass heater.
    reply
      Bookmark Topic Watch Topic
    • New Topic