views:

1060

answers:

1

How to Expire a Cookie in 30 min ? I am using a jquery cookie. I am able to do something like this.

$.cookie("example", "foo", { expires: 1 });

This is for 1 day. But how can we set expiry time to 30 min. Please help. Thank you.

+5  A: 

30 minutes is 30 * 60 * 1000 miliseconds. Add that to the current date to specify an expiration date 30 minutes in the future.

 var date = new Date();
 date.setTime(date.getTime() + (30 * 60 * 1000));
 $.cookie("example", "foo", { expires: date });
Sinan Ünür
Thank You so much Sinan...It works !!!
kalyan