-1

How can I find the difference between today's date and a future date, eg:2014/12/31, in JQuery so that I can display the days, hours, minutes and seconds left per second in HTML classed div tags?

The HTML would look like this:

<div id="hours">00</div>
<div id="days">00</div>
<div id="minutes">00</div>
<div id="seconds">00</div>

Like a countdown timer.

proPhet
  • 1,188
  • 4
  • 16
  • 39
  • 1
    There are *so many* duplicates of this question that it's hard to pick the best one. Did you look through all of those and find nothing? – Pointy Nov 28 '14 at 15:40
  • Check http://keith-wood.name/countdown.html or http://trulycode.com/bytes/easy-countdown-to-date-with-javascript-jquery/ – vaso123 Nov 28 '14 at 15:43
  • @Pointy, I only checked pluggins, I want an idea of how to build the app myself. Did you even read through the others? Did you read through mine? – proPhet Nov 28 '14 at 15:50
  • @lolka_bolka, thanks, fantastic link, will definitely have a look! Will update – proPhet Nov 28 '14 at 15:51
  • @proPhet of *course* I read through your question; it's only a few lines long. There are dozens of other questions on the same topic. Have you, for example, read through [the documentation for the Date API](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date?redirectlocale=en-US&redirectslug=JavaScript%2FReference%2FGlobal_Objects%2FDate)? – Pointy Nov 28 '14 at 15:52
  • @Pointy, yes indeed, definitely good information there! My question, though, is how to **find the difference** from the values obtained using the methods and processes delineated in your reference. – proPhet Nov 28 '14 at 15:57
  • lol, I swear if I come to an acceptable answer first I will assume your reputation is wasted... #pompus? – proPhet Nov 28 '14 at 16:01
  • It may in fact be a combination of comments by Pointy and lolka_bolka that will support the production of an answer to this question. – proPhet Nov 28 '14 at 16:10
  • 1
    Old questions: [1968167](http://stackoverflow.com/questions/1968167) [3224834](http://stackoverflow.com/questions/3224834) [41948](http://stackoverflow.com/questions/41948) [13894632](http://stackoverflow.com/questions/13894632) [14612919](http://stackoverflow.com/questions/14612919) - there are many more. – Pointy Nov 28 '14 at 16:15
  • @Pointy, thanks! those links helped a lot! I must not have looked around thoroughly enough. – proPhet Dec 01 '14 at 11:04

1 Answers1

1

Take momentjs it is really easy for tasks like this.

var a = moment([2007, 0, 29]);
var b = moment([2007, 0, 28]);
a.diff(b, 'days') // 1
svenhornberg
  • 14,376
  • 9
  • 40
  • 56