I hardcoded date string in one variable and passing this in new Date()
let hardcoded = "10/4/2018 12:00:00 AM";
console.log($.type(hardcoded)); // String is printing
console.log(hardcoded); // 10/4/2018 12:00:00 AM is printing
var d = new Date(hardcoded);
console.log(d); // Thu Oct 04 2018 00:00:00 GMT+0530 (India Standard Time) is printing
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Here in variable 'd' i am getting proper date .. no any issue.
But in below case same string i am getting in convertedDate variable what i hardcode above but its not working ..
let convertedDate = new Date().toLocaleString("en-us", {
timeZone: 'UTC'
});
console.log($.type(convertedDate)); // String is printing
console.log(convertedDate); // 6/26/2019 12:02:50 PM is printing
var d = new Date(convertedDate);
console.log(d)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
but here in variable d :- "Invalid date" is coming..