設置3小時設置cookie到期後3小時
我有這樣的JavaScript代碼後,一個cookie過期:
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*2*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
我怎樣才能讓在3小時後該cookie過期嗎?
該代碼是誤導...該餅乾喔ld過期'days * 2 hours' - 因此,調用像'createCookie(「blah」,「fred」,1.5)這樣的函數可以做到這一點 –
把'days * 2 * 60 * 60 * 1000'改爲'days * 24 * 60 * 60 * 1000',然後調用函數createCookie('name','value',0.125)。 – Marvin
[Set a cookie expire after 2 hours]可能的重複(http://stackoverflow.com/questions/19068812/set-a-cookie-expire-after-2-hours) –