如何使用 JavaScript 從今天開始減日期?


你需要使用`new Date().getDate()`獲取當前日期。語法如下所示 -

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

更新於:2020 年 9 月 10 日

914 次瀏覽

開啟您的職業生涯

完成課程獲取認證

開始
廣告
© . All rights reserved.