它用於使用isBefore()函數檢查某個時刻是否在另一個時刻之前,以檢查某個日期是否在Node.js中的特定日期之前。如果尚未解析,則第一個參數將被瞬間解析。
用法:
moment().isBefore(Moment|String|Number|Date|Array); moment().isBefore(Moment|String|Number|Date|Array, String);
參數:它可以保存Moment | String | Number | Date | Array。
返回:對或錯
moment模塊的安裝:
- 您可以訪問“安裝力矩”模塊的鏈接。您可以使用此命令安裝此軟件包。
npm install moment
- 安裝 moment模塊後,可以使用命令在命令提示符下檢查力矩版本。
npm version moment
- 之後,您可以僅創建一個文件夾並添加一個文件,例如index.js。要運行此文件,您需要運行以下命令。
node index.js
範例1: 文件名:index.js
// Requiring module
const moment = require('moment');
var bool1 = moment('2010-10-20')
.isBefore('2010-10-21'); // true
console.log(bool1);
var bool2 = moment('2010-10-20')
.isBefore('2010-12-31', 'year'); // false
console.log(bool2);
運行程序的步驟:
- 項目結構將如下所示:
- 確保使用以下命令安裝了moment模塊:
npm install moment
- 使用以下命令運行index.js文件:
node index.js
輸出:
true false
範例2: 文件名:index.js
// Requiring module
const moment = require('moment');
function checkIsBefore(date1, date2) {
return moment(date1).isBefore(date2);
}
var bool = checkIsBefore('2010-10-20', '2010-10-21');
console.log(bool);
使用以下命令運行index.js文件:
node index.js
輸出:
true
相關用法
- d3.js zip()用法及代碼示例
- PHP pi( )用法及代碼示例
- d3.js d3.min()用法及代碼示例
- PHP pow( )用法及代碼示例
- PHP Ds\Set xor()用法及代碼示例
- d3.js d3.set.has()用法及代碼示例
- PHP ord()用法及代碼示例
- p5.js mag()用法及代碼示例
- PHP Ds\Map xor()用法及代碼示例
- p5.js value()用法及代碼示例
- PHP Ds\Map put()用法及代碼示例
- p5.js nfp()用法及代碼示例
- PHP Ds\Set last()用法及代碼示例
- PHP Ds\Set add()用法及代碼示例
- PHP Ds\Set first()用法及代碼示例
注:本文由純淨天空篩選整理自gouravhammad大神的英文原創作品 Moment.js isBefore() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。