简体   繁体   中英

JS Date comparison CET with GMT

I don't understand...

I have the following code:

console.log(stats.mtime); // Tue Dec 30 2014 17:03:48 GMT+0100 (CET)
console.log(s3Info.LastModified); // Tue, 30 Dec 2014 15:46:37 GMT
console.log(stats.mtime == s3Info.LastModified); // false
console.log(stats.mtime > s3Info.LastModified); // false
console.log(stats.mtime < s3Info.LastModified); // false

How can I compare those dates? I tried to convert to timestamps but it won't work. I get a TypeError: Object Tue, 30 Dec 2014 15:46:37 GMT has no method 'getTime' error.

Using nodejs but (hopefully) the answer would be similar clientside.

Thanks

What about comparing the unix time like:

stats.mtime.getTime() === s3Info.LastModified.valueOf()

im assuming the stats as in fs stat, and LastModified as the JS Date obj

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM