Lodash是一個JavaScript庫,可在underscore.js之上運行。 Lodash幫助處理數組,字符串,對象,數字等。
_.isValidDate()方法用於檢查給定值是否為有效日期。檢查該值是否既是Date對象的實例,又是該Date對象表示有效日期。
注意:此方法不驗證Date的原始輸入是否為真實日期。例如,日期字符串“02/30/2014”被視為有效日期,因為Date對象將其解釋為日期表示形式“03/02/2014”,這是正確的。像Moment.js這樣的庫可用於驗證表示日期的字符串。
用法:
_.isValidDate( value )
參數:此方法接受如上所述和以下描述的單個參數:
- value:此參數保存需要為有效日期檢查的值。
返回值:此方法返回一個布爾值。如果給定值是有效日期,則返回true;否則,返回false。
注意:由於它需要安裝lodash contrib庫,因此在正常的JavaScript中將無法使用。可以使用npm install lodash-contrib -save安裝Lodash contrib庫。
範例1:
Javascript
// Defining Lodash variable
const _ = require('lodash-contrib');
var validDate = new Date("10/02/2014");
var invalidDate = new Date("10/32/2014");
// Checking for Valid Date Object
console.log("The Value of Valid Date:" +
_.isValidDate(validDate));
console.log("The Value of Invalid Date:" +
_.isValidDate(invalidDate));
輸出:
The Value of Valid Date:true The Value of Invalid Date:false
範例2:
Javascript
// Defining Lodash-contrib variable
const _ = require('lodash-contrib');
var val = "World War 2";
// Checking for Valid Date Object
console.log("The Value of Date:" +
_.isValidDate(val));
輸出:
The Value of Date:false
相關用法
- Lodash _.method()用法及代碼示例
- Lodash _.sneq()用法及代碼示例
- Lodash _.toQuery()用法及代碼示例
- Lodash _.uniqWith()用法及代碼示例
- Lodash _.xorWith()用法及代碼示例
- Lodash _.head()用法及代碼示例
- Lodash _.remove()用法及代碼示例
- Lodash _.pullAt()用法及代碼示例
- Lodash _.pullAll()用法及代碼示例
- Lodash _.pull()用法及代碼示例
- Lodash _.nth()用法及代碼示例
- Lodash _.takeRight()用法及代碼示例
- Lodash _.take()用法及代碼示例
- Lodash _.sortedLastIndex()用法及代碼示例
- Lodash _.fromPairs()用法及代碼示例
- Lodash _.differenceWith()用法及代碼示例
- Lodash _.castArray()用法及代碼示例
- Lodash _.cloneDeep()用法及代碼示例
- Lodash _.clone()用法及代碼示例
- Lodash _.sampleSize()用法及代碼示例
- Lodash _.find()用法及代碼示例
- Lodash _.zipWith()用法及代碼示例
- Lodash _.zipObject()用法及代碼示例
- Lodash _.xor()用法及代碼示例
注:本文由純淨天空篩選整理自epistler_999大神的英文原創作品 Lodash _.isValidDate() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。