Question

I am trying to keep track of the days since the birth of my program in epoch days. So, I I give my program:

epochProgram = 15622 // epoch day number that this program was born.

I then get the current time and divide by 1000 to make it seconds. Then I take that and divide it by the number of seconds per a day which is 86400 to convert it to the number of days today since epoch. I then subtract the program epoch birthday number from today's epoch number to see how many days have lapse since the birth of the program.

dateObj = new Date();   
 var biz = parseInt(dateObj.getTime()/1000));
  biz = biz/86400-epochProgram;

Lets say a few days have past and biz=6.30. My issue is this: 12:00 am is at 6.30, at 5:00PM biz=7.0, and at 11:PM, biz=7.2.

Why does the tenths .# digit work as .3 is the start of the say and .2 is the end of the day? What could I do to fix this so I can have a correct day increment?

PS: this is local Pacific time.

Was it helpful?

Solution

Subtract the timezone offset:

var biz = (dateObj.getTime() - dateObj.getTimezoneOffset() * 6e4) / 1000 >>> 0;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top