Date formatting parse error Java -


i want format date sun apr 10 07:05:45 mdt 2017 2017-04-10t07:05:45.24z.

i using following:

datetimeformatter formatter = datetimeformatter.ofpattern("eee-lll-dd h:mm:sszuuuu"); formatter.parse(date); 

date in format given above.
getting parse error @ index 3

there multiple issues. correct pattern "eee mmm dd hh:mm:ss z uuuu"

  • need use m instead of l - i'm investigating why @ moment. see datetimeformatter month pattern letter "l" fails. if .format("lll") returns 4, in 4th month.
  • need use spaces instead of -
  • need spaces between s, z , uuuu
  • need use hh not h
  • april 10th monday, not sunday

see example code run live @ ideone.com.

string input = "mon apr 10 07:05:45 mdt 2017" ; datetimeformatter f = datetimeformatter.ofpattern( "eee mmm dd hh:mm:ss z uuuu" , locale.us ); zoneddatetime zdt = zoneddatetime.parse( input , f ); 

zdt.tostring(): 2017-04-10t07:05:45-06:00[america/denver]


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -