IE 11 - Date is not working [duplicate]

北战南征 提交于 2020-02-23 09:42:27

问题


  1. new Date().toLocaleDateString('en-US'); // "‎8‎/‎17‎/‎2018"
  2. new Date("8/17/2018") //valid date
  3. new Date(new Date().toLocaleDateString('en-US')) // Invalid Date

I am trying to create date from local date string (see screenshot) but its not working in IE11 only. It works with normal date string though.

I know something wrong with "" double quotes but not able to get it working.

Any suggestion ?


回答1:


Seems it can be done like this

new Date(new Date().toLocaleDateString('en-US').replace(/[^ -~]/g,''))

Reference Answer




回答2:


just use momentjs for this.

moment("8/17/2018", "L").format() would output:
"2018-08-17T00:00:00+02:00"

(+02:00 is my local timezone. you can specify to use utc or another timezone too.)

also keep in mind L is dependent on the timezone profile you installed. this is the default en one.

you could also replace "L" with "MM/DD/YYYY"

the second argument of moment always specifies the format of your input.
it is also able to guess the input but you need to experiment with that.

.format("L") is essentially the same but in the output direction.



来源:https://stackoverflow.com/questions/51892603/ie-11-date-is-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!