从日期中删除秒/毫秒并转换为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
热门推荐
1 带狗狗训练
4 听力训练狗狗
6 怎训练狗狗
7 腹肌训练狗狗
8 网球训练狗狗
9 记叙文训练狗狗
10 狗狗太凶怎么训练
11 核心力量训练狗狗
12 狗狗乱叫怎么训练
13 发音训练狗狗
14 怎么训练狗狗叼东西给主人
15 荆州训练狗狗
16 篮球训练狗狗
17 做训练狗狗
18 训练狗狗坐姿