Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
9
rated 0 times [  15] [ 6]  / answers: 1 / hits: 18675  / 12 Years ago, fri, october 5, 2012, 12:00:00

I need the epoch time in days. I've seen posts on how to translate it to date but none in days. I'm pretty bad with epoch time...how could I get this?


More From » epoch

 Answers
14

I need the epoch time in days




I'll interpret that you want the number of days since the epoch. The epoch itself is day zero (or the start of day 1, however you want to view it).



At the heart of a javascript Date object is a number of milliseconds since 1970-01-01T00:00:00Z. So to get the number of days from then to now you simply get the current time value and divide it by the number of milliseconds in one day:



var now = new Date();
var fullDaysSinceEpoch = Math.floor(now/8.64e7);


For 2012-10-05 you should get 15618. Not sure if it allows for leap seconds and such, but it should be close enough (within a few seconds) if the system clock is accurate.



It is only when reading values of a Date object (such as getHours() and toString()) that the timezone offset is applied to give local times.


[#82746] Wednesday, October 3, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
elishaannac

Total Points: 28
Total Questions: 97
Total Answers: 101

Location: Samoa
Member since Mon, Nov 8, 2021
3 Years ago
elishaannac questions
Sun, Dec 5, 21, 00:00, 3 Years ago
Mon, Jun 14, 21, 00:00, 3 Years ago
Mon, Jul 22, 19, 00:00, 5 Years ago
Mon, Jul 8, 19, 00:00, 5 Years ago
;