Cant Fromat String To Date
When I try to convert a string value to a Date I get the error message 'Invalid date' timestamp : string = '2017:03:22 08:45:22'; . . let time = new Date(timestamp); console.log('T
Solution 1:
Since your string must be in ISO date format you can change it like in the code below:
let timestamp : string = "2017:03:22 08:45:22";
let timestampISO : string = timestamp.replace(':','-').replace(':','-').replace(' ','T');
let time = newDate(timestampISO);
console.log("Time: ",time);
Solution 2:
Your date must be a version of an ISO format.
To be more specific, it must be a version of ISO8601. See more here.
Example:
let time = newDate("2017/03/22 08:45:22");
Post a Comment for "Cant Fromat String To Date"