How do you get the unix timestamp for the start of today in javascript?

Well, the cleanest and fastest way to do this is with:

long timestamp = 1314297250;
long beginOfDay = timestamp - (timestamp % 86400);

where 86400 is the number of seconds in one day


var now = new Date; // now

now.setHours(0);   // set hours to 0
now.setMinutes(0); // set minutes to 0
now.setSeconds(0); // set seconds to 0

var startOfDay = Math.floor(now / 1000); // divide by 1000, truncate milliseconds

var now = new Date();
var startOfDay = new Date(now.getFullYear(), now.getMonth(), now.getDate());
var timestamp = startOfDay / 1000;

var d = new Date();
d.setHours(0);
d.setMinutes(0);
d.setSeconds(0);
d.setMilliseconds(0);
var t = d / 1000;