Forum Moderators: open

Message Too Old, No Replies

set date 4 cookies

how to estab ED

         

antipodes

5:57 am on Mar 2, 2003 (gmt 0)

10+ Year Member



I am learning js (module) but the resource did not exactly explain how to change the date expiry.

I have ExpireDate.setTime (ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));

then on to the

document.cookie = NameOfCookie + "=" + escape(value) +
((expiredays == null)? "" : "; expires=" + ExpireDate.toGMTString());
}

function delCookie (NameOfCookie) {
if (getCookie(NameOfCookie)) {
document.cookie = NameOfCookie + "=" +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}

It wasn't explained what 3600 or 1000 is. Or how the date 01 Jan 1970 was arrived at. Could some kind person help me with this.

It's all a mystery until u work out how.

Thanks
antipodes

hakre

11:52 am on Mar 2, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hi antipodes,

i'll take it upside down ;):

3600: seconds per hour (60*60)
1000: milliseconds

so the count of expiredays is multiplicated to get a value of days in milliseconds. this is needed.

i do not know, if the first line of code you wrote is right, but you have to define a date var first. here are some lines of code you can use, too:

var ExpireDate= new Date();
var ExpireTime= ExpireDate.getTime() + ( expiredays * 24 * 3600 * 1000);
ExpireDate.setTime(ExpireTime);

this code should solve your problem.