比較也是很簡單!直接做比較運算子就好!
let nowDate: Date = new Date();
let endDate: Date = new Date( "2021-10-15T12:00:00+00:00");
let myDate: Date = new Date( "2021-10-15T16:22:00");
console.log(nowDate);
console.log(endDate);
console.log(myDate);
if (nowDate > endDate){
console.log("Bigger");
}else{
console.log("Smaller");
}
if (nowDate > myDate){
console.log("Bigger");
}else{
console.log("Smaller");
}
結果:
[LOG]: nowDate: "2021-10-15T08:22:47.110Z" [LOG]: endDate: "2021-10-15T12:00:00.000Z" [LOG]: myDate: "2021-10-15T08:22:00.000Z" [LOG]: nowDate vs endDate => "Smaller" [LOG]: nowDate vs myDate => "Bigger"
沒有留言:
張貼留言
歡迎大家留言提問,我會答的都會盡力回答!
如果太久沒出現回應就是我又忘記回來看留言了TAT