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();
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();
Share
Improve this question
asked Aug 17, 2015 at 20:58
ChipeChipe
4,81110 gold badges39 silver badges65 bronze badges
2
- 1 possible duplicate of How do I get the number of days between two dates in JavaScript? and Get difference between 2 dates in javascript? – Alon Amir Commented Aug 17, 2015 at 21:04
- possible duplicate of How do I get the number of days between two dates in JavaScript? – bytecode77 Commented Aug 18, 2015 at 6:12
1 Answer
Reset to default 11Divide 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;