I have an app where I don't care about time zones and need only UTC time. This means my timestamps need to match UTC time.
My goal is to get 2 UTC timestamps for current day. Let's say UTC time is June 21st 13:04:47.
For this time I would like to get timestamp for midnight of that day June 21st 00:00:00 and timestamp for 24 hours later June 22nd 00:00:00. Timestamps for those two times are 1466467200000 and 1466553600000.
This is how I am currently doing it:
var today = new Date();
var todayStart = new Date(Date.UTC(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate(), 0, 0, 0));
var todayEnd = new Date();
todayEnd.setTime(todayStart.getTime() + (24 * 60 * 60 * 1000));
console.log("start of the day: " + todayStart.getTime())
console.log("end of the day: " + todayEnd.getTime());
This returns correct results but I am wondering is this reliable and is it the right way to accomplish what I want. Thank you for your help.