Reputation: 1107
I am trying to implement sending a 304 header for performance in a server hosting program I am writing, but I do not know how to parse the date of the If-Modified-Since header. I also would like to know how to find out if the If-Modified-Since date is older/newer than another date that I have in my code.
Upvotes: 3
Views: 3495
Reputation: 1107
To parse the date, use new Date(datestring)
or Date.parse(datestring)
. To see if a date is newer or older than another date, use the greater than (>) and less than (<) operators.
Upvotes: 3
Reputation: 16843
Just in case if someone comes across...
"Last-Modified"
you can use Date constructor that takes a date string.NaN
)."Last-Modified"
or "If-Modified-Since"
header you can use Date's toUTCString() method.var date = new Date("Wed, 17 May 2017 04:44:36 GMT");
var ms = Date.parse("Wed, 17 May 2017 04:44:36 GMT");
console.log('parsed date: ', date);
console.log('parsed date ms: ', ms);
console.log('If-Modified-Since: '+date.toUTCString());
Upvotes: 6