JRS: In article <>, dated Thu,
19 May 2005 13:44:17, seen in news:comp.lang.javascript, Stephen
Chalmers <> posted :
>To determine the expiry date, read the current time in milliseconds with
>Date.getTime(), add to it the total number of milliseconds in the number of
>days duration you require,
That cannot be known reliably and accurately in general.
> then pass that value to the Date() constructor to
>generate a new object equating to your desired expiry date. Call
>.toGMTString for the new object, and append its return value to the
>'expires' parameter when writing the cookie.
>
>So for a 30-day cookie you could write:
>
>document.cookie = "kysely=1; expires=" + new Date( new
>Date().getTime()+86400000*30 ).toGMTString();
It will overrun an hour of civil time in Spring, and underrun an hour in
Autumn, in many locations.
D = new Date() ; D.setDate(D.getDate()+30)
document.cookie = "kysely=1; expires=" + D.toGMTString();
or
with (new Date()) { setDate(getDate()+30)
document.cookie = "kysely=1; expires=" + toGMTString() }
When using 86400000 I prefer to write 864e5; shorter, and no risk of
miscounting zeroes.
Code containing that number disregards Summer Time, more often than not.
Of course, for many purposes an hour in a month does not matter; but the
code might be copied with a shorter interval, and an unwary programmer
might not consider the difference between "this expires in 24 hours" and
"this expires at this time tomorrow.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
|