如何在 JavaScript 中从今天的日期中减去 date?
javascriptweb developmentobject oriented programming更新于 2025/11/14 13:32:17
您需要借助 new Date().getDate() 使用 currentDate。语法如下 −
var anyVariableName= yourCurrentDate - yourSubstractDateOfCurrentMonth;
示例
var currentDate=new Date().getDate();
var substractDate=new Date("2020-07-01").getDate();
const numberOfDaysInCurrentMonthOnly = currentDate-substractDate;
console.log(numberOfDaysInCurrentMonthOnly);
注意
Today’s date is - 28-07-2020
要运行上述程序,您需要使用以下命令 −
node fileName.js.
这里我的文件名是 demo129.js
PS C:\Users\Amit\JavaScript-code> node demo129.js 27
相关文章
有用资源
javascript 参考教程 - 该教程包含有关 javascript 的更多信息:https://www.cainiaomax.com/javascript/

