How to set javascript cookie to expire after 10 years?

The function I use sets the cookie expiration in this part of the code:

time += 3600 * 1000;

Expires in an hour. How to set this to expire after 10 years?

+3
source share
3 answers

Well, how much:

  • hours a day?
  • days a year?
  • years in a decade?

Answer:

time += 3600 * 1000 * 24 * 365 * 10;
+13
source
var CookieDate = new Date;
CookieDate.setFullYear(CookieDate.getFullYear( ) +10);
document.cookie = 'myCookie=to_be_deleted; expires=' + CookieDate.toGMTString( ) + ';';
+30
source

This will

time += (3600 * 1000)*87660

8766 - the number of hours per year. Accurate measurement: 8,765.81277 hours

+4
source

All Articles