我正在尝试设置具有 ISOString 格式的日期,但毫秒应设置为两位数。
如果 ISOString 返回 2021-11-02T05:49:12.704ZI 希望它是 2021-11-02T05:49:12.70Z (毫秒四舍五入到两个位置)
这就是我想要做的。
let startdate = new Date();
console.log(startdate.getMilliseconds()); //just to check
let d = startdate.toString().replace(microsecond=Math.round(startdate.microsecond, 2))
console.log(d) //format is different
startdate = startdate.toISOString() //this is different than d
console.log(startdate)
输出为
961
Tue Nov 02 2021 05:50:46 GMT+0000 (Coordinated Universal Time)
2021-11-02T05:50:46.961Z
任何人都可以帮忙吗?