How can I set the cookie to expire at this date: 19 Jan 2038 ?
The cookie is not set if I try like this:
$.cookie('test', true, {expires: "2038-01-19, 03:14:08 UTC"});
How can I set the cookie to expire at this date: 19 Jan 2038 ?
The cookie is not set if I try like this:
$.cookie('test', true, {expires: "2038-01-19, 03:14:08 UTC"});
I found the solution:
var date = new Date();
date.setFullYear(2038);
$.cookie('test', true, {expires: date});
Calculate the number of days from current date to the Date you want your cookie to expire and then set that 'days' value to set the cookie expiry.
var start = new Date();
var end = new Date("19 Jan 2038");
// end - start returns difference in milliseconds
var diff = new Date(end - start);
// get days
var days = diff/1000/60/60/24;
use this
document.cookie = "username=John Doe; expires=Tue, 19 Jan 2038 12:00:00 UTC";
function setUserConfigInCookie(){
var expireDate = new Date;
expireDate.setDate(expireDate.getDate() + 7); // It expires in a week
var options = {
path: '/',
expiresAt: expireDate
}
userConfig = {}; // This is a valid JSON object that you need to save in a cookie
$.cookies.set( 'userConfig', userConfig, options);
// console.log('Expires=' + expireDate.toGMTString());
}