当我尝试将字符串值转换为日期时,我收到错误消息"无效日期"
timestamp : string = "2017:03:22 08:45:22";
.
.
let time = new Date(timestamp);
console.log("Time: ",time); //here I get Time: Invalid date
答案 0 :(得分:1)
由于您的字符串必须是ISO日期格式,您可以像下面的代码中那样更改它:
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);

答案 1 :(得分:0)