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

推荐订阅源

D
Darknet – Hacking Tools, Hacker News & Cyber Security
NISL@THU
NISL@THU
S
Securelist
O
OpenAI News
S
Security Affairs
Cyberwarzone
Cyberwarzone
T
Threatpost
Simon Willison's Weblog
Simon Willison's Weblog
The Last Watchdog
The Last Watchdog
L
LINUX DO - 最新话题
C
Cisco Blogs
PCI Perspectives
PCI Perspectives
SecWiki News
SecWiki News
S
Secure Thoughts
GbyAI
GbyAI
I
Intezer
AWS News Blog
AWS News Blog
F
Fortinet All Blogs
I
InfoQ
阮一峰的网络日志
阮一峰的网络日志
Google Online Security Blog
Google Online Security Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
A
About on SuperTechFans
S
Schneier on Security
P
Proofpoint News Feed
雷峰网
雷峰网
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
小众软件
小众软件
H
Heimdal Security Blog
Microsoft Security Blog
Microsoft Security Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
T
The Exploit Database - CXSecurity.com
T
Threat Research - Cisco Blogs
V
V2EX
L
Lohrmann on Cybersecurity
Security Latest
Security Latest
A
Arctic Wolf
Apple Machine Learning Research
Apple Machine Learning Research
H
Hacker News: Front Page
Cisco Talos Blog
Cisco Talos Blog
Webroot Blog
Webroot Blog
T
Tenable Blog
MyScale Blog
MyScale Blog
博客园 - 司徒正美
S
SegmentFault 最新的问题
Y
Y Combinator Blog
腾讯CDC
Hacker News: Ask HN
Hacker News: Ask HN
M
MIT News - Artificial intelligence
G
GRAHAM CLULEY

博客园 - 豆豆の爸爸

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());

(完)