Skip to content

Set cookies to expire in 1 hour in JavaScript

Advertisements

Learn how you can extend the life of a cookie beyond the current browser session by setting an expiration date and saving the expiry date within the cookie. This can be done by setting the ‘expires’ attribute to a date and time.

var now = new Date();
now.setTime(now.getTime() + 1 * 3600 * 1000);
let cookieVal = escape(document.myform.customer.value) + ";"
document.cookie="name=" + cookieVal;
document.cookie = "expires=" + now.toUTCString() + ";"
document.write ("Setting Cookies : " + "name=" + cookieVal );
See also  Permuting Two Arrays - Hackerrank Challenge - Java Solution

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.