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
What does a cookie with 1969 as the expiration date mean?
提问by AGamePlayer
回答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),则令到期时间为最早的可表示日期和时间。否则,让到期时间为当前日期和时间加上增量秒秒。


