javascript 有效期为 1969 年的 cookie 是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/51497459/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 09:34:16  来源:igfitidea点击:

What does a cookie with 1969 as the expiration date mean?

javascriptcookies

提问by AGamePlayer

enter image description here

在此处输入图片说明

How can a cookie expire in 1969?

cookie 如何在 1969 年过期?

What does this mean?

这是什么意思?

Thanks,

谢谢,

回答by Jonas Wilms

Unix time was started at the beginning of 1970, that means that -1is in 1969. And that is a commonly used value for "unknown" if the expected value is usually positive. And for cookies MaxAge with a negative value means that the cookie expires as soon as the browser gets closed:

Unix 时间开始于 1970 年初,即-11969 年。如果期望值通常为正,则这是“未知”的常用值。对于具有负值的 cookie MaxAge 意味着只要浏览器关闭,cookie 就会过期:

Relevant section of the spec:

规范的相关部分:

5.2.2 [..] If delta-seconds is less than or equal to zero (0), let expiry-time be the earliest representable date and time. Otherwise, let the expiry-time be the current date and time plus delta-seconds seconds.

5.2.2 [..] 如果 delta-seconds 小于或等于零 (0),则令到期时间为最早的可表示日期和时间。否则,让到期时间为当前日期和时间加上增量秒秒。