如何在午夜使用 Jquery 使 Cookie 过期? [英] How to expire a Cookie using Jquery at midnight?

查看:20
本文介绍了如何在午夜使用 Jquery 使 Cookie 过期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这样做了:

$.cookie("ultOS", (i), {expires:1});

但它只会在第二天到期.

But it will only expire next day.

如何让 cookie 在午夜过期?

How can I expire a cookie at midnight?

这会起作用吗?

var date = new Date();
var midnight = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59);
$.cookie("ultOS", (i), {expires: midnight});

推荐答案

我觉得这样可以:

var currentDate = new Date();
expirationDate = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate()+1, 0, 0, 0);
$.cookie("ultOS", "5", {expires: expirationDate});

这篇关于如何在午夜使用 Jquery 使 Cookie 过期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆