Hereâs how I did it. Expires=date: Expiration Date for cookie ; Default expiration date is until expiration of client (web browser) Max-age=seconds : Similar to Expires but in seconds ; Have a priority over Expires If you provide this attribute with a valid date or time, then the cookie will expire on a given date or time and thereafter, the cookies' value will not be accessible. If we wanted to delete the userId cookie from previous examples, here is how we'd do it: Javascript Set Cookie. Variable for setting a Cookies Expires Value. If you need to store a session expiration client side, it needs to be encrypted in the value of the cookie, so again needs to be created server-side, not by JavaScript, because the server must be the only place the value can be decrypted in order for it to be secure. I wanted it for 90 days. cookie property like this. javascript check cookie expiration (6) We want to store User's Authorization information in cookie which should not be lost upon refresh (F5) of browser. That code kept the cookie for 1 year. We can use date.toUTCString to get it. You can create cookies using document. expires UTC Date format expected; Example: Thu, 26 Mar 2015 15:26:23 GMT; Can be easily generated from a Javascript date object with the toUTCString() method You can delete a cookie by giving it an empty value and setting its expiration date to any time in the past. The parameters of the function above are the name of the cookie (cname), the value of the cookie (cvalue), and the number of days until the cookie should expire (exdays). expires=Tue, 19 Jan 2038 03:14:07 GMT; The cookie expiration date defines the time, when the browser will automatically delete it. I know google has one that like expires in 2035 or something but I would like this on to last long. The âexpiresâ attribute is optional. A cookie is a key/value pair and you cannot create more than one at a time using the same string. The expiry on the cookie is not sufficient, as it can be changed by the client. javascript - expire - How to set expiration date for cookie in AngularJS . I recommend using the date right before unix epoch time will extend passed a 32-bit integer. document.cookie = "cookiename=cookievalue" You can even add expiry date to your cookie so that the particular cookie will be removed from the computer on the specified date. So, I changed that part of the code, but I wanted to verify if I did it correctly and the cookie expiration date is indeed set to 90 days. Delete Cookies. If you donât set an expiration date the cookie will expire at the end of the userâs session. Hello, I am using jQuery to set a cookie and the expiration date is: Code: date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); which lasts for 1 day, but I would like the cookie to not expire for a long time, is this possible? The cookie gets set and the cookievalue gets written properly however the expiration date is ignored by chrome and chrome reports the expiration as a session, which removes the cookie ⦠The expires option in a JavaScript cookie is optional. The expiry date should be set in the UTC/GMT format. The function sets a cookie by adding together the cookiename, the cookie value, and the expires string. In the process, I also changed the JavaScript cookie code with a better one â taken from Stack Overflow, of course. The bottom line is that I soon found that historically there have been two ways to set an expiration date in a cookie â expires or max-age. The date must be exactly in this format, in the GMT timezone. To let cookies survive a browser close, we can set either the expires or max-age option. When creating a new cookie, the semicolon is used to provide additional parameters such as an expiration date, or a path, not declare multiple cookies at a time.