[英]Get the difference between to dates in minutes with Date-FNS - NaN Error
我正在使用Date-FNS庫來獲取分鍾之間的日期之間的差異。 為什么minutesDifference返回NaN ? 我的目標是獲取給定日期之間的分鍾數。 這是指向Date-FNS文檔的鏈接。
getDateTime: function () {
var now = new Date()
var year = now.getFullYear()
var month = now.getMonth()
var day = now.getDate()
var hour = now.getHours()
var minute = now.getMinutes()
var dateTime = year + ', ' + month + ', ' + day + ', ' + hour + ', ' + minute + ', 0'
var minutesDifference = differenceInMinutes(new Date(2018, 2, 30, 22, 55, 0), new Date(dateTime))
return minutesDifference
},
您的dateTime
值是一個不正確的字符串,您向Date()
傳遞了1個單一參數,而不是6個不同的參數。
做就是了
differenceInMinutes(new Date(2018, 2, 30, 22, 55, 0), new Date())
默認情況下, new Date
將采用當前日期/時間戳,因此您無需將任何參數傳遞給它。
請參考文檔: Date
-JavaScript | MDN
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.