1

If I am given an end date in epoch time, how do I use the current time to calculate the days left before the end epoch time given?

Epoch time given example:

1444958355000

Getting current day in epoch:

var day = new Date();
var time = day.getTime();
Chipe
  • 4,641
  • 10
  • 36
  • 64
  • 1
    possible duplicate of [How do I get the number of days between two dates in JavaScript?](http://stackoverflow.com/questions/542938) and [Get difference between 2 dates in javascript?](http://stackoverflow.com/questions/3224834) – Alon Amir Aug 17 '15 at 21:04
  • possible duplicate of [How do I get the number of days between two dates in JavaScript?](http://stackoverflow.com/questions/542938/how-do-i-get-the-number-of-days-between-two-dates-in-javascript) – bytecode77 Aug 18 '15 at 06:12

1 Answers1

11

Divide by 1000 to get seconds, then by 60 for minutes, then by 60 for hours, then by 24 for days:

var timeleft = 1444958355000 - (new Date()).getTime();
var days = Math.ceil((((timeleft / 1000) / 60) / 60) / 24)
//days = 60;
tymeJV
  • 103,943
  • 14
  • 161
  • 157