Node.js 日期和时间 Date.addMinutes() 方法
date-and-time.Date.addMinutes()方法用于将额外的分钟添加到现有日期和时间。
所需模块:通过 npm 安装模块或在本地使用它。
- 通过使用 npm:
npm install date-and-time --save
- 通过使用 CDN 链接:
句法:
const addMinutes(dateObj, minutes)
参数:此方法采用以下参数作为参数:
- dateobject:日期的字符串对象。
- 分钟:这是要添加的分钟数。
返回值:此方法返回更新的日期和时间。
示例 1:
index.js
// Node.js program to demonstrate the
// Date.addMinutes() method
// Importing date-and-time module
const date = require('date-and-time')
// Creating object of current date and time
// by using Date()
const now = new Date();
// Adding Minutes to the existing
// date and time by using
//date.addMinutes() method
const value = date.addMinutes(now,24);
// Display the result
console.log("updated date and time :- " + value)
index.js
// Node.js program to demonstrate the
// Date.addMinutes() method
// Importing date-and-time module
const date = require('date-and-time')
// Creating object of current date and time
// by using Date()
const now = new Date();
now.setDate(20)
// Adding Minutes to the existing date and time
// by using date.addMinutes() method
const value = date.addMinutes(now,30);
// Display the result
console.log("updated date and time :- " + value)
使用以下命令运行index.js文件:
node index.js
输出:
updated date and time :- Fri Mar 19 2021 18:38:26 GMT+0530 (India Standard Time)
示例 2:
index.js
// Node.js program to demonstrate the
// Date.addMinutes() method
// Importing date-and-time module
const date = require('date-and-time')
// Creating object of current date and time
// by using Date()
const now = new Date();
now.setDate(20)
// Adding Minutes to the existing date and time
// by using date.addMinutes() method
const value = date.addMinutes(now,30);
// Display the result
console.log("updated date and time :- " + value)
使用以下命令运行index.js文件:
node index.js
输出:
updated date and time :- Sat Mar 20 2021 18:04:43 GMT+0530 (India Standard Time)
参考:https://github.com/knowledgecode/date-and-time#addminutesdateobj-minutes