Shopping days before jQuery Christmas counter

How to calculate shopping days before the Christmas counter in jQuery. must be added to the site. need fast and dirty. no partiaulcar date to match

you need to ignore the weekend, of course, or maybe not from your website. um

I can’t believe that it’s not here anymore.

happy holidays everyone!

+5
source share
3 answers

You can easily build a function to get the number of days left until a date:

function daysUntil(year, month, day) {
  var now = new Date(),
      dateEnd = new Date(year, month - 1, day), // months are zero-based
      days = (dateEnd - now) / 1000/60/60/24;   // convert milliseconds to days

  return Math.round(days);
}

daysUntil(2009, 12, 25); // 19 days!!
+12
source

jQuery , . .

0

CMS :

<html>
<head>

<script language="javascript">
function daysUntil() {
    var now = new Date();
    var year = now.getFullYear();
    var month = '12';
    var day = '25';
    dateEnd = new Date(year, month - 1, day), // months are zero-based
    days = (dateEnd - now) / 1000/60/60/24;   // convert milliseconds to days
    document.getElementById('xmas').innerHTML = 'Days until Christmas: ' + Math.round(days);
}
</script>
</head>
<body>
<div id="xmas"></div>
<script language="javascript">
daysUntil();
</script>
</body>
</html>
0