date-and-time.Date.addDays()是用于操作 JS 日期和时间模块的极简函数集合,用于将额外的天数添加到现有日期和时间。
所需模块:通过 npm 安装模块或在本地使用它。
- 通过使用 npm。
 
npm install date-and-time --save
- 通过使用 CDN 链接。
 
<script src="/path/to/date-and-time.min.js"></script>
用法:
addDays(dateObj, days)
参数:此方法采用以下参数作为参数:
- dateobject:它是日期的字符串对象。
 - days:这是天数。
 
返回值:此方法返回更新的日期和时间。
范例1:
index.js
// Node.js program to demonstrate the  
// Date.addDays() method
  
// Importing module
const date = require('date-and-time')
  
// Creating object of current date and time 
// by using Date() 
const now = new Date();
  
// Adding Days to the existing date and time
// by using date.addDays() method
const value = date.addDays(now, 24);
  
// Display the result
console.log("updated date and time:" + value)使用以下命令运行index.js文件:
node index.js
输出:
updated date and time: Wed Mar 31 2021 20:07:07 GMT+0530 (India Standard Time)
范例2:
index.js
// Node.js program to demonstrate the  
// Date.addDays() method
  
// Importing 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 Days to the existing date and time
// by using date.addDays() method
const value = date.addDays(now, 24);
  
// Display the result
console.log("updated date and time:" + value)使用以下命令运行index.js文件:
node index.js
输出:
updated date and time: Tue Apr 13 2021 20:09:57 GMT+0530 (India Standard Time)
参考: https://github.com/knowledgecode/date-and-time#adddaysdateobj-days
相关用法
- Node.js GM drawLine()用法及代码示例
 - Node.js GM drawArc()用法及代码示例
 - Node.js GM drawPolyline()用法及代码示例
 - Node.js GM drawBezier()用法及代码示例
 - Node.js GM drawCircle()用法及代码示例
 - Node.js GM drawEllipse()用法及代码示例
 
注:本文由纯净天空筛选整理自RohitPrasad3大神的英文原创作品 Node.js Date.addDays() API。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
