Khilen Maniyar
Khilen Maniyar

Reputation: 2579

Getting "Invalid Date" when passing dynamic date in IE 11 only in Javascript

Creating date using dynamically generated date string throws invalid date message only in IE11.

Example

var today = new Date();
var ag_endDate = new Date(today).toLocaleDateString('en-US');
var final = new Date(ag_endDate);
console.log(final);

Upvotes: 2

Views: 1684

Answers (1)

gurvinder372
gurvinder372

Reputation: 68393

try this

var dateObj = new Date();
var usFormatDate = dateObj.toLocaleDateString('en-US'); 
console.log( usFormatDate );

sorry, my bad! date constructor does take date Object as parameter.

However, if your intention is to simply get the formatted date in en-US locale, then you don't have to create another date object for the same.

Upvotes: 2

Related Questions