2
我有這樣的功能:如何使用Typescript檢查Date數據類型變量是否過去?
isAuthenticationExpired = (expirationDate: Date) => {
var now = new Date();
if (expirationDate - now > 0) {
return false;
} else {
return true;
}
}
兩個expirationDate
和now
是Date類型的
打字稿給我一個錯誤說:
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.
我如何檢查日期已過期我的方式似乎不工作?
您可以直接使用' - '不減去日期。但你可以這樣做:'expirationDate.getTime()> now.getTime()' – techfoobar