我有这个功能:
isAuthenticationExpired = (expirationDate: Date) => {
var now = new Date();
if (expirationDate - now > 0) {
return false;
} else {
return true;
}
}
expirationDate
和now
均为日期类型typescript 给我一个错误,说:
Error 3 The left-hand side of an arithmetic operation must be of type
'any', 'number' or an enum type.
Error 4 The right-hand side of an arithmetic operation must be of type
'any', 'number' or an enum type.
由于我的方式似乎不起作用,如何检查日期是否已过期?
最佳答案
使用now
获取日期expirationDate
和.valueOf()
的整数值表示形式(自unix纪元以来的毫秒数)
var now = new Date().valueOf();
expirationDate = expirationDate.valueOf();
或者,使用
Date.now()