惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

AWS News Blog
AWS News Blog
T
Tenable Blog
Project Zero
Project Zero
T
The Exploit Database - CXSecurity.com
L
LINUX DO - 热门话题
T
Threat Research - Cisco Blogs
T
Threatpost
Security Latest
Security Latest
C
Cisco Blogs
L
Lohrmann on Cybersecurity
S
Security @ Cisco Blogs
Google Online Security Blog
Google Online Security Blog
NISL@THU
NISL@THU
AI
AI
V
Vulnerabilities – Threatpost
Google DeepMind News
Google DeepMind News
C
Cyber Attacks, Cyber Crime and Cyber Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
The Last Watchdog
The Last Watchdog
G
GRAHAM CLULEY
Cloudbric
Cloudbric
H
Hackread – Cybersecurity News, Data Breaches, AI and More
H
Hacker News: Front Page
U
Unit 42
A
Arctic Wolf
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
MyScale Blog
MyScale Blog
O
OpenAI News
Scott Helme
Scott Helme
V2EX - 技术
V2EX - 技术
P
Proofpoint News Feed
博客园 - 叶小钗
Hugging Face - Blog
Hugging Face - Blog
云风的 BLOG
云风的 BLOG
V
Visual Studio Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Cyberwarzone
Cyberwarzone
博客园 - 【当耐特】
H
Heimdal Security Blog
S
Schneier on Security
阮一峰的网络日志
阮一峰的网络日志
Help Net Security
Help Net Security
D
DataBreaches.Net
Y
Y Combinator Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
TaoSecurity Blog
TaoSecurity Blog
K
Kaspersky official blog
N
News and Events Feed by Topic
WordPress大学
WordPress大学
P
Palo Alto Networks Blog

博客园 - 豆豆の爸爸

IDEA 2024的零卡死配置 10分钟揭秘大模型的原理 苹果容器Apple container是做什么用的? pnpm 10.14 支持JavaScript运行时的安装了 白话Docker:用Web应用实例深入容器 用 rake 合并多个 JS 文件,并且用 Google Closure Compiler 压缩代码 HTML 5 就是 Web Application JS程序员的一天 Google Map 类实例在类式继承中的实现 “当 HTML 5 来敲门”专题沙龙(上海)活动 PHP 的 Smarty 模板页中分离JS并避开literal标签的解决方法 Google Maps(Google 地图) V3 在 IE7 浏览器中拖放其容器时图块被覆盖的 bug 2010年我的个人总结 [译]用 Closure Compiler 编写更好的 OO 的 JavaScript 使用 IronScheme 进入 Scheme 编程语言的世界 - 豆豆の爸爸 《JS高级程序设计(第2版)》书评 [译]在 Firebug 中的表格化日志 在 Notepad++ 运行 Closure Linter 来校验JS代码 在 Notepad++ 运行 Closure Compiler 工具来解析并压缩JS
写入 cookie 的过期时间时在GMT或UTC时间格式上的兼容问题
豆豆の爸爸 · 2011-03-17 · via 博客园 - 豆豆の爸爸

用 JavaScript中的 Date 类,可以得到格式为“年/月/日 时:分:秒”的当前本地时间。这种格式是合法的,可以用静态方法 Date.parse() 解析的,否则返回NaN的话,说明格式为非法,不能解析。

从北京时间转换成GMT/UTC时间有8个小时的时间差。计算方法为:

UTC时间 + 时间差(+8) = 本地时间

兼容问题为:

在 web 浏览器中写入cookie的过期时间的实现是不同的。Google chrome 浏览器会把转换成GMT/UTC后的时间写入cookie的过期时间,而IE和FF浏览器还是把本地时间写入cookie的过期时间,toGMTString()/toUTCString()没有起作用了。

写入cookie的函数JS代码如下:

function setCookie(key, val, expires, domain, path, secure){
    if (!path) path = '/';
    
    document.cookie = 
        key + '=' + encodeURIComponent(val)
        + (expires ? '; expires=' + expires : '')
        + (domain ? '; domain=' + domain : '')
        + (path ? '; path=' + path : '')
        + (secure ? '; secure' : '');
}

写入cookie的代码如下:

var dat = new Date();
var dateTime = dat.getFullYear()+'/'+(dat.getMonth()+1)+'/'+(dat.getDate()+1)+ ' 8:00:00';
setCookie('bookInfoCounts', counts, new Date(Date.parse(dateTime)).toUTCString());

(完)