View Full Version : Javascript code help
OptWizard
17-11-2003, 08:02/08:02AM
var expDays = 1; // number of days the cookie should last
var expDate = new Date();
expDate.setTime(expDate.getTime() + (24 * 10 * 60 * 1000 * expDays));
How can I set this to expire after 1 hour?
qwerty
17-11-2003, 08:39/08:39AM
I don't know the first thing about writing cookies, but try this page: http://www.comptechdoc.org/independent/web/cgi/javamanual/javacookie.html
polarmate
17-11-2003, 08:44/08:44AM
To begin with there is an error in the code you posted. It should be:
var expDays = 1; // number of days the cookie should last
var expDate = new Date();
expDate.setTime(expDate.getTime() + (24 * 60 * 60 * 1000 * expDays));This sets a cookie to expire after 1 day.
If you want it to expire in 1 hour, all you need is:
var expDate = new Date();
expDate.setTime(expDate.getTime() + (60 * 60 * 1000));
60 minutes in an hour, 60 seconds in a minute and 1000 milliseconds in a second so 60*60*1000 = one hour
vBulletin® v3.8.3, Copyright ©2000-2010, Jelsoft Enterprises Ltd.