以下是设置cookie的JavaScript代码,时效到第二天零点:

// 获取当前日期时间
var currentDate = new Date();
// 获取明天零点时间
var tomorrowDate = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate()+1, 0, 0, 0);
// 计算cookie时效时间
var expires = "expires=" + tomorrowDate.toUTCString();
// 设置cookie
document.cookie = "cookieName=cookieValue; " + expires;

上述代码中,我们首先获取当前日期时间,然后获取明天的零点时间,再将其转换为UTC时间字符串作为cookie的时效时间,最后设置cookie即可。

帮我写个javascript的cookie设置时效到第二天零点

原文地址: https://www.cveoy.top/t/topic/b25U 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录