Y
Y
Ya7dro2022-01-03 23:42:39
HTTP Cookies
Ya7dro, 2022-01-03 23:42:39

How to set cookie expiration?

Hello! Can you please tell me how to correctly set the cookie lifetime to 1 year instead of the existing short lifetime during the session?
Here is a piece of code:
cookieSet() {
const date = new Date();
date.setTime(`${date.getTime()}${(365 * 30 * 24 * 60 * 60 * 1000)}`);
let expiryDate = `expiryDate=" ${date.toUTCString()}`;
document.cookie = `${this.dataSettings.cookie_name}=true; ${expiryDate}; path=/`;
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question