In comp.lang.javascript message <11**********************@11g2000cwr.goog
legroups.com>, Tue, 16 Jan 2007 00:18:52, dd <dd****@gmail.composted:
>var exp=new Date();
var numdays=7;
exp.setTime(exp.getTime()+(1000*60*60*24*numdays) );
document.cookie="MyCookie=1; path=; expires="+exp.toGMTString();
That's not a good way to increment a date.
Firstly, you could use 864e5 instead of 1000*60*60*24
Secondly, the innermost parentheses are unnecessary.
Thirdly, in many countries for about 4% of the time that will not give 7
civil days. Often the exact expiry does not matter, but there is a
possibility of the user coming to expect it.
exp.setDate(exp.getDate()+numdays);
This is actually a case where "with" can be used in safety :
with (new Date()) {
var numdays = 7
setDate(getDate() + numdays)
document.cookie="MyCookie=1; path=; expires=" + toGMTString() }
It's a good idea to read the newsgroup and its FAQ. See below.
--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.