<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
</body>
</html>
<script>
var odate= new Date()
odate.setDate(odate.getDate()+5)
document.write(odate)
document.cookie="username=leo"
document.cookie = 'age=32;expires=' + oDate.toGMTString()
document.cookie="age=32;expires="+odate//在document.cookie = '名称=值;expires=' +时间;中前半部分已经是字符串了,应该会进行隐式类型转换字符串时间的,为什么还要oDate.toGMTString()?
</script>
问题:在cookie中过期时间:document.cookie = '名称=值;expires=' + 字符串格式的时间; 中的字符串格式的时间为什么要使用 oDate.toGMTString();这个形式呢?在document.cookie = '名称=值;expires=' +时间;中前半部分('名称=值;expires=')已经是字符串了,应该会进行隐式类型转换时间的,为什么还要oDate.toGMTString()?
var oDate = new Date() 出来的是本地时间(中国东八区)
oDate.toGMTString()已废弃,严格来说是 oDate.toUTCString()。转化成的是零时区的UTC时间。