![]() ![]() The !isNaN(Date.parse(d)) silently rejects the improper date value and logs the value that are successful in conversion. Hence if the stringsFromAPI was a value coming from the backend, then the above function will convert only those dates that conform to the acceptable format. Hence, it will not be understood by the Date.parse() function nor by the new Date() function. ![]() Note that here the date 20-11-2021 is of the format DD-MM-YYYY. Use the Date.parse() Function to Convert String to Date in JavaScript In case we are using a value passed from the backend via API for conversion, we should make sure that the format passed is as understood by the new Date() function, and it is good to have a check that new Date() returns a valid date object.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |