我的日期字符串格式为 '2020/02/25 23:58:08' 。我想将其解析为“2020-02-25”。
注意:最初日期是字符串格式,转换后无论是日期还是字符串格式都没有关系。
file.js
function test (filepath) {
let date = "2020/02/25 23:58:08";
date = date.replace("//"/gi,"-");
// I am not familiar with regular expressions, I want to omit the data related to hours, seconds extra
}
当我运行程序时,我得到了Uncaught ReferenceError: gi is not Defined, gi is to global replacement
最佳答案
试试这个
let date = "2020/02/25 23:58:08";
var date2 = new Date(date)
console.log(date2.toISOString().slice(0,10))
关于javascript - 如何解析 YYYY-MM-DD 格式的日期字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60399318/