Reputation: 661
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("Time: ",time); //here I get Time: Invalid date
Upvotes: 0
Views: 65
Reputation: 2251
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 = new Date(timestampISO);
console.log("Time: ",time);
Upvotes: 1