- Basic HTML
document.cookie = "cookieName= true; expires=Fri, 31 Dec 9999 23:59:59 GMT";
NOTE: But browsers have a problem with the dates after 2038-01-19 04:14:07 as the Unix epoch time exceeds 32-bit int. This problem is also called the Year 2038 problem (also called Y2038, Epochalypse, Y2k38, or Unix Y2K).
Hence, the maximum value you can set as an expiry date for a cookie that is supported by the majority of web browsers is:
231 - 1 = 2147483647 ie. 2038-01-19 04:14:07
document.cookie = "cookieName= true; expires=Tue, 19 Jan 2038 04:14:07 GMT"; // OR const cookieName = "something"; const cookieValue = "something"; const daysToExpire = new Date(2147483647 * 1000).toUTCString(); document.cookie = cookieName + '=' + cookieValue + '; expires=' + daysToExpire;
Please Login to comment...