0

this is my first post but I was a little unclear about formatting after reading the other posts about this. Below is my Javascript code, I am trying to set the longest possible expiration date.

function setCookie(cname, cvalue) {
  var expires = "expires=" + new Date(2147483647 * 1000).toUTCString();
  document.cookie = cname + "=" + cvalue + "; " + expires;
}

Is this correct?

Do I put:

"expires=" + new Date(2147483647 * 1000).toUTCString();

or just

 "expires=" + "2147483647";
jack
  • 31
  • 4

1 Answers1

0

The latest possible date is so far into the future you probably wouldn't want that!

let maxDate = new Date(8640000000000000).toUTCString();
console.log(maxDate);

//Result:
Sat, 13 Sep 275760 00:00:00 GMT

Normally, a max date would be 31 Dec 2099

ATD
  • 1,344
  • 1
  • 4
  • 8
  • This is crazy old but the timestamp for Thu 31 Dec 2009 23:59:59 is 4102444799000 for all of you copy-and-pasters. – mboyde Jun 09 '22 at 19:33