PDA

View Full Version : How to set the cookie with an expiration date?



Elijah
5 May 2010, 9:39 AM
Here is the API ( String name, Mixed value, [Object expires], [String path], [String domain], [Boolean secure] ) :
If I wanted to store the value 'Elijah' in a cookie how do I actually set this with a date expiration?


new Ext.util.Cookies.set("myCookieName", "Elijah", {expires:'05/22/2010'});
does not work.

How do I get the date into it?

rohangpatil
5 May 2010, 9:47 AM
Check out ExtJs date formatting.. expires should be a date object it seems.. so... new Date() can be used...

Elijah
5 May 2010, 10:02 AM
Well I tried.


var dt = new Date('5/22/2010 03:05:01 PM GMT-0600'
new Ext.util.Cookies.set("myCookieName", "Elijah", {expires:dt});

but this does not work either
Can someone just post a slice of code that functions? I am using FireFox 3.6

rohangpatil
5 May 2010, 10:04 AM
no no just give new Date('date in GMT format')
try this
new Ext.util.Cookies.set("myCookieName", "Elijah", new Date('5/22/2010 03:05:01 PM GMT-0600'));

Elijah
5 May 2010, 10:15 AM
Thank you!
The way I was wrongly interpreting the API was that expire was a variable set in an object thus {expire:'1/11/2010'}
Thats just the way I think. If it were written as [Object Date] and the api specified that this 3rd argument was the expiration date then I would have thought it to be the JavaScript Date object. But specified as Object expire well it must be some ExtJS thing so do as I did.

Wrong :) oh well. LOL.

Thank you again.

rohangpatil
5 May 2010, 10:18 AM
Its k :)
ExtJs needs some time to understand..For me also Documentation is sometimes hard to interpret :P