set midnight in javascript for cookie expiration

499 Views Asked by At

Good morning, I currently have this script:

now = new Date (). getTime ();
now = now + 86400000;

this takes the current date and time and adds 24 hours to it.

Instead, I would need to set midnight of the current day. I tried with:

var d = new Date ();
date = d.setHours (0,0,0,0);
now = date / 1000;

but it does not work! I need this to set the expiration of a cookie:

$ .cookies.set ('mycookie2250', 'true', {expiresAt: new Date (now)});

in the first case it works but in the second it doesn't. Where am I wrong?

1

There are 1 best solutions below

2
Nico On
var date = new Date();
date.setHours(0,0,0,0);

// date is midnight.