java - DateTimeFormatterBuilder with specified parseDefaulting conflicts for YEAR field -


i have following formatter:

datetimeformatter formatter = new datetimeformatterbuilder()         .appendpattern("yyyymm")         .parsedefaulting(chronofield.second_of_minute, 0)         .parsedefaulting(chronofield.minute_of_hour, 0)         .parsedefaulting(chronofield.hour_of_day, 0)         .parsedefaulting(chronofield.day_of_month, 1)         .parsedefaulting(chronofield.month_of_year, 1)         .parsedefaulting(chronofield.year, zoneddatetime.now().getyear())         .toformatter()         .withzone(zoneid.systemdefault()); 

i try parse string "201505"

system.out.println(zoneddatetime.parse("201505", formatter)); 

and throws exception:

caused by: java.time.datetimeexception: conflict found: year 2016 differs year 2015

it works if comment out setting of default value year.

as far understood documentation, should try replace default value if there no value parsed. seems works month have different month default 1 parsed. doesn't work year.

am using wrong tell me if there different way define default values fields might not present in pattern?

the problem pattern letter "y" refers chronofield.year_of_era, not chronofield.year. change last parsedefaulting line:

.parsedefaulting(chronofield.year_of_era, zoneddatetime.now().getyear()) 

and should work.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -