Reputation: 2615
I need to set a cookie to expire at midnight of the day that it is set, but I'm struggling to get my head about jQuery Date();
.
I'm using the jQuery Cookie plugin to control the cookies. By default it just accepts an int
as the expiry time, but you can pass it a date object according to the docs. So I'm trying to use jQuery Date();
and edit just the hrs
mins
secs
to set it to 23:59:59
.
When I use Date it outputs something like this: Mon Oct 28 2013 10:59:30 GMT+0000 (GMT)
Does anyone know how to hook into just the hours, mins and seconds part of this?
Thanks!
Upvotes: 0
Views: 2186
Reputation: 2615
Fix:
var date = new Date();
date.setHours(23,59,59,0);
// set the new item as a cookie
$.cookie(count, newItem, { expires: date });
Changes Mon Oct 28 2013 11:17:55 GMT+0000 (GMT)
to Mon Oct 28 2013 23:59:59 GMT+0000 (GMT)
Upvotes: 3