On the compatibility of toLocalDateString () methods in IE browsers

for the year, month and day obtained by the toLocalDateString () method, the early morning timestamp of the day is obtained through new Date (). A Invalid Date error occurs in the IE browser, but if you write the same date string directly, you will get a normal timestamp. What is the reason? The code is as follows

   

ask the boss to help with the answer!

Jun.15,2022

the date on the left is timeString , and the date on the right is hand-typed, but it is not equal when all the dates are string .
print out the length of timeString , you will find that the actual length is 15
clipboard.png

15,IE11toLocaleDateString
clipboard.png

under IE11 .

solution: keep only numbers and symbols -/ , and exclude all others
date.toLocaleDateString (). Replace (/ (year | month) / gdepartment'/). Replace ('day','). Replace (/ / [^\ Dmurf /] / gjingjue')

the above recommendation does not use toLocaleDateString or similar api` Because the results returned by different languages are different https://stackoverflow.com/que...
document
https://developer.mozilla.org...

Menu