在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ 隱式類型轉(zhuǎn)換的問題

隱式類型轉(zhuǎn)換的問題

<!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=' +時(shí)間;中前半部分已經(jīng)是字符串了,應(yīng)該會(huì)進(jìn)行隱式類型轉(zhuǎn)換字符串時(shí)間的,為什么還要oDate.toGMTString()?
</script>
問題:在cookie中過期時(shí)間:document.cookie = '名稱=值;expires=' + 字符串格式的時(shí)間; 中的字符串格式的時(shí)間為什么要使用 oDate.toGMTString();這個(gè)形式呢?在document.cookie = '名稱=值;expires=' +時(shí)間;中前半部分('名稱=值;expires=')已經(jīng)是字符串了,應(yīng)該會(huì)進(jìn)行隱式類型轉(zhuǎn)換時(shí)間的,為什么還要oDate.toGMTString()?

回答
編輯回答
墨小白

var oDate = new Date() 出來的是本地時(shí)間(中國東八區(qū))
oDate.toGMTString()已廢棄,嚴(yán)格來說是 oDate.toUTCString()。轉(zhuǎn)化成的是零時(shí)區(qū)的UTC時(shí)間。

2017年4月12日 17:48
編輯回答
兮顏

這個(gè)東西輸出一下就知道了,這并不是轉(zhuǎn)換字符串是轉(zhuǎn)換時(shí)區(qū)

var odate= new Date()
console.log(odate.toString())
console.log(odate.toGMTString())
2017年2月26日 06:07