'Time-based expiration After 30 minutes of inactivity and At midnight
I created a cookie function to set 30-minute cookies. And it's working.
I want to alter the code and want to handle a single case. The cookie should expire automatically at midnight (or 12 a.m.). (i.e., if the cookie is set at 11:45, it should expire at midnight and after 12 a.m. new cookie should be set)
So it should work fine in both cases with a 30-minute cookie and a midnight expiration.
Code Example:
**
function set30MinuteCookie(cname, cvalue) {
var d = new Date();
d.setTime(d.getTime() + 30 * 60 * 1000);
var expires = "expires=" + d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires;
}
set30MinuteCookie();
**
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
