Reputation: 117
The function I'm using sets the cookie expiration in this part of the code:
time += 3600 * 1000;
It expires in an hour. How to set this to expire in 10 years?
Upvotes: 9
Views: 39004
Reputation: 17094
Note: toGMTString() is deprecated since Jun 23, 2017, 9:04:01 AM and should no longer be used. It remains implemented only for backward compatibility; please use toUTCString() instead.
For more information: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toGMTString
var CookieDate = new Date;
CookieDate.setFullYear(CookieDate.getFullYear() +10);
document.cookie = 'myCookie=to_be_deleted; expires=' + CookieDate.toGMTString() + ';';
You can still achieve the same result just by replacing toGMTString()
with toUTCString()
as so:
var CookieDate = new Date;
CookieDate.setFullYear(CookieDate.getFullYear() +10);
document.cookie = 'myCookie=to_be_deleted; expires=' + CookieDate.toUTCString() + ';';
Upvotes: 49
Reputation: 892
It will be
time += (3600 * 1000)*87660
8766 is the number of hours in year. The precise measurement is: 8 765.81277 hours
Upvotes: 4
Reputation: 19560
Well, how many:
Answer:
time += 3600 * 1000 * 24 * 365 * 10;
Upvotes: 20