Skip to content
Advertisement

Error: Text ‘1/31/2020’ could not be parsed at index 0 while trying to parse string date

I have a date as string as below

JavaScript

I am using the below code

JavaScript

I am getting the below Exception when excuting this code:

JavaScript

Can someone help me what I am doing wrong here?

Advertisement

Answer

You should pass 01/31/2020or update the format to M/dd/yyyy

DateTimeFormatter documentation

The month is considered as a number and in the documentation :

Number: If the count of letters is one, then the value is output using the minimum number of digits and without padding. Otherwise, the count of digits is used as the width of the output field, with the value zero-padded as necessary.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement