You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Result of TimeZone.getDefault(): sun.util.calendar.ZoneInfo[id="UTC",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null]
Result of DateTimeZone.getDefault(): UTC
Problem description
SimpleDateFormatter is dependent on the Locale and in particular for the pattern yyyy-'W'ww, it will return different weeks numbers:
jshell> new java.text.SimpleDateFormat("yyyy-'W'ww", Locale.US).format(new Date(2022-1900, 12-1, 26))
$11 ==> "2022-W53"
jshell> new java.text.SimpleDateFormat("yyyy-'W'ww", Locale.UK).format(new Date(2022-1900, 12-1, 26))
$12 ==> "2022-W52"
On the other hand, DateTimeFormatter.forPattern will refuse, even when using Locale.US, to parse week 53 and anyway will return an incorrect date for the US locale and one of the week before.
Test case
The following works for Locale.UK but not Locale.US:
The text was updated successfully, but these errors were encountered:
victornoel
changed the title
DateTimeFormatter.forPattern inconsistecy with US Locale and SimpleDateFormatter when parsing weeks
DateTimeFormatter.forPattern inconsistency with US Locale and SimpleDateFormatter when parsing weeks
Sep 27, 2024
Key information
TimeZone.getDefault()
:sun.util.calendar.ZoneInfo[id="UTC",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null]
DateTimeZone.getDefault()
:UTC
Problem description
SimpleDateFormatter
is dependent on theLocale
and in particular for the patternyyyy-'W'ww
, it will return different weeks numbers:On the other hand,
DateTimeFormatter.forPattern
will refuse, even when usingLocale.US
, to parse week 53 and anyway will return an incorrect date for the US locale and one of the week before.Test case
The following works for Locale.UK but not Locale.US:
The text was updated successfully, but these errors were encountered: