从日期中删除秒/毫秒并转换为ISO字符串?
首先让我们获取当前日期-
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
热门推荐
10 圣诞祝福语简短小学
11 祖国七十华诞简短祝福语
12 老师送的祝福语简短
13 生日祝福语大全女生简短
14 祝女性生日祝福语简短
15 牛年女神节祝福语简短
16 情人表白祝福语简短大气
17 老公开业祝福语简短
18 官宣新年祝福语简短