2014-02-13 59 views
0

我想用這個設置在JavaScript中cookie的JavaScript getDay()從今天起一年設置cookie

document.cookie=cookie_name+"="+YouEntered+"; expires=Saturday, 04-Apr-2015 05:00:00 GMT";

,我注意到它需要一個到期日期(與星期幾)在未來某個時候。我發現getDay()檢索當天的當前星期幾,但是有沒有辦法將日期設置爲JavaScript中的未來日期,並從該未來日期獲取星期幾?

+0

'someDateObject.setFullYear(someDateObject.getFullYear()+ 1)' – CBroe

+0

試過,但它返回1423865040509. – pandoragami

+1

那麼你當然得事後_format_它...'toGMTString' – CBroe

回答

0
<title>JavaScript Get Date</title> 
<SCRIPT LANGUAGE="JavaScript"> 
    var currentTime = new Date();    
     var year = currentTime.setFullYear(currentTime.getFullYear()+1); 

    document.write(currentTime.toUTCString(year)); 
</SCRIPT> 
<style type = "text/css"> 
body 
{ 
    background-color: white; 
} 
</style> 
</head> 
<body> 
</body> 
</html>