Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IE 11 - Date is not working [duplicate]

  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 ?

enter image description here

like image 957
Dipak Telangre Avatar asked Aug 17 '18 09:08

Dipak Telangre


2 Answers

Seems it can be done like this

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

Snapshot from ie11

Reference Answer

like image 101
brk Avatar answered Nov 14 '22 22:11

brk


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.

like image 25
GottZ Avatar answered Nov 14 '22 23:11

GottZ