圣诞节前的购物日柜台 jQuery

发布于 2024-08-13 19:54:28 字数 138 浏览 8 评论 0原文

如何在 jQuery 中计算圣诞节前的购物天数。需要添加到网站。 需要快速而肮脏。 它不需要对应需要忽略周末的特定日期

当然, - 或者可能不需要,因为它是一个网站。嗯,

不敢相信这里已经没有人了。

大家节日快乐!

How to calculate shopping days till christmas counter in jQuery. need to add to website.
need quick and dirty. no partiaulcar date it needs to correspond to

needs to ignore weekends of course - or maybe not since its for a website. hmm

cant believe there isnt one on here already.

happy holidays everyone!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

街道布景 2024-08-20 19:54:29

我使用 这个 jQuery 插件 来显示倒计时,设置起来非常简单。 此页面上提供了使用示例。

I've used this jQuery plugin to display countdowns, it's pretty simple to set up. A usage example is available on this page.

ㄖ落Θ余辉 2024-08-20 19:54:29

稍微修改一下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>

Modified CMS's code a bit:

<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>
初心未许 2024-08-20 19:54:28

您可以轻松构建一个函数来获取距离某个日期还剩多少天:

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!!

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!!
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文