0
我想比較實際的日期這樣的格式,我從服務器接收:我怎樣才能得到這種格式的實際日期?
item.expires_date.slice 「2016年11月28日22點10分57秒ETC/GMT」在javascript這怎麼可能?專爲部分ETC/GMT
在這種情況下我只是想比較2016年11月28日 我怎麼能做到這一點:
var today = new Date().toISOString().slice(0, 10);
if(item.expires_date.slice(0, 10) > today) {
console.log("This item have expired");
} else {
console.log("this item has not expired");
}
}
這是行不通的,因爲它帶來的項目尚未過期比較日期: 2016-11-28 - 2016-12-28 謝謝!
謝謝我使用了部分代碼 – arnoldssss
要小心,剝離時區部分意味着它將被視爲本地,因此表示每個時區具有不同偏移量的不同時刻。那是需要的嗎?或者它應該始終是GMT? – RobG
等/沒有任何偏移量的GMT是UTC日期,應該這樣解析,當區域設置日期與UTC不同時(通常情況下),上述代碼將失敗。請參閱[本答案](http://stackoverflow.com/questions/7303580/understanding-the-etc-gmt-time-zone)瞭解有關Etc/GMT的更多信息。 –