Skip to main content
Question

Bug with conversion Date to TO String

  • December 30, 2024
  • 1 reply
  • 56 views

Forum|alt.badge.img+1

Today I faced one issue.

While convert System.Date to To String with “YYYY” format. it is returning result “2025” and if you use “yyyy” then it is returning “2024”.

This is happen on 30th of Dec 2024. 

 

Please let me know the permanent solution.

 

Thanks

 

 

 

1 reply

Forum|alt.badge.img+5
  • Navigator | Tier 3
  • 36 replies
  • December 30, 2024

This is not a bug.

 

From the DateTimeFormatter documentation:, indicating the symbol, meaning and examples:

Y week-based-year year 1996; 96

So you're formatting the week-based-year, not the regular year. December 30th 2019 belongs to the first week of 2020, hence your output.

Use yyyy (year-of-era) or uuuu (year) instead of YYYY and you'll get 2019 instead.

Basically, YYYY should usually be used with w (week-of-week-based-year) and E (day-of-week).

Source: java - DateTimeFormatter adding a year to date after formatting - Stack Overflow


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings