date-and-time.Date.isSameDay() 方法用於檢查給定的日期是否相同。
所需模塊:通過 npm 安裝模塊或在本地使用它。
- 通過使用 npm:
npm install date-and-time --save
- 通過使用 CDN 鏈接:
<script src="/path/to/date-and-time.min.js"></script>
用法:
isSameDay(date1, date2)
參數:此方法采用以下參數-
- date1:它持有 date1 的對象。
- date2:它持有 date2 的對象。
返回值:當且僅當兩個日期相同時,此方法才返回布爾值 true。
範例1:
index.js
// Node.js program to demonstrate the
// Date.isSameDay() APi
// Importing http module
const date = require('date-and-time')
// Creating object of current date
// and time by using Date()
const now1 = new Date();
// Creating object of current date
// and time using Date() method
const now2 = new Date();
// Checking if both dates are same or not
// by using date.isSameDay() api
const value = date.isSameDay(now1,now2);
// Display the result
if(value)
console.log("Both dates are same")
else
console.log("Both dates are not same")
使用以下命令運行index.js文件:
node index.js
輸出:
Both dates are same
範例2:
Javascript
// Node.js program to demonstrate the
// Date.isSameDay() APi
// Importing http module
const date = require('date-and-time')
// Creating object of current date
// and time using Date() method
const now1 = new Date();
// Creating object of current date and time
// by using Date() method
const now2 = new Date();
now1.setFullYear(2016)
// Checking if both dates are same or not
// by using date.isSameDay() method
const value = date.isSameDay(now1,now2);
// Display the result
if(value)
console.log("Both dates are same")
else
console.log("Both dates are not same")
使用以下命令運行index.js文件:
node index.js
輸出:
Both dates are not same
參考: https://github.com/knowledgecode/date-and-time#issamedaydate1-date2
相關用法
- Node.js console.timeLog()用法及代碼示例
- Node.js x509.toLegacyObject()用法及代碼示例
- Node.js fs.fsyncSync()用法及代碼示例
- Node.js process.nextTick()用法及代碼示例
- Node.js GM drawLine()用法及代碼示例
- Node.js GM drawArc()用法及代碼示例
- Node.js GM drawPolyline()用法及代碼示例
- Node.js GM drawBezier()用法及代碼示例
注:本文由純淨天空篩選整理自RohitPrasad3大神的英文原創作品 Node.js date-and-time Date.isSameDay() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。