首先让我们获取当前日期-
var currentDate = new Date();
console.log("当前日期如下="+currentDate);现在,让我们使用setSeconds()-将秒/毫秒设置为0,以删除秒/毫秒:
currentDate.setSeconds(0,0);
使用toISOString()-转换为ISO字符串-
currentDate.toISOString()
现在让我们看到带有输出的完整代码-
var currentDate = new Date();
console.log("The current date is as follows="+currentDate);
currentDate.setSeconds(0,0);
console.log("从日期中删除秒后,新日期为=");
console.log(currentDate.toISOString());要运行以上程序,您需要使用以下命令-
node fileName.js.
在这里,我的文件名为demo143.js。
输出结果
这将产生以下输出-
PS C:\Users\Amit\JavaScript-code> node demo143.js The current date is as follows=Sat Aug 01 2020 18:20:09 GMT+0530 (India Standard Time) 从日期中删除秒后,新日期为= 2020-08-01T12:50:00.000Z