I want to compare the actual date to a format like this that I'm receiving from a server: item.expires_date.slice "2016-11-28 22:10:57 Etc/GMT"
In javascript how could this be possible? specially for the part Etc/GMT
In the case I just wanted to compare 2016-11-28 how can I achieve this:
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" );
}
}
it does not work because it brings to item has not expired comparing dates: 2016-11-28 - 2016-12-28 Thanks!
Since "Etc/GMT" is the same as "GMT+00:00", you can remove it and create a Date
object from the string:
var s = "2016-11-28 22:10:57 Etc/GMT"; var d = new Date(Date.parse(s.replace("Etc/", ""))); console.log(d.toString());
Then you can compare d
to the current date.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.