In comp.lang.javas cript message <11************ **********@11g2 000cwr.goog
legroups.com>, Tue, 16 Jan 2007 00:18:52, dd <dd****@gmail.c omposted:
>var exp=new Date();
var numdays=7;
exp.setTime(ex p.getTime()+(10 00*60*60*24*num days));
document.cooki e="MyCookie=1 ; path=; expires="+exp.t oGMTString();
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()+numd ays);
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.c om/faq/index.html>.
<URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.