在jQuery倒计时器中更改日期

时间:2016-10-10 08:41:58

标签: javascript jquery date simpledateformat countdowntimer

我的网站上有一个简单的倒数计时器。

我想将日期从1月25日改为10月24日格林尼治标准时间上午9点?

演示:http://codepen.io/anon/pen/xEWJpY

我做了很多谷歌搜索,但对于需要改变的内容非常困惑。

$(function () {
	var austDay = new Date();
	austDay = new Date(austDay.getFullYear() + 1, 1 - 1, 26);
	$('#defaultCountdown').countdown({until: austDay});
	$('#year').text(austDay.getFullYear());
});
#defaultCountdown { width: 240px; height: 45px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1>jQuery Countdown Basics</h1>

<p><strong>25th January</strong> == austDay = new Date(austDay.getFullYear() + 1, 1 - 1, 26);</p>

<div id="defaultCountdown"></div>

<hr>

<p>&nbsp;</p>

<p>What is October 24th at 9am?</p>

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:2)

只需要使用

new Date(year, month, day, hours, minutes, seconds, milliseconds)

将在2016年10月24日之前给予反击。

var austDay = new Date();
austDay = new Date(austDay.getFullYear(), 10-1, 24, 9, 0);

FYI,

  • 这只是一个例子,您可以根据需要进行必要的更改。
  • 请不要忘记在下面的示例中添加countdown plugin以获取输出。

希望这有帮助。

$(function () {
	var austDay = new Date();
	austDay = new Date(austDay.getFullYear(), 10-1, 24, 9, 0);
	$('#defaultCountdown').countdown({until: austDay});
	$('#year').text(austDay.getFullYear());
});
#defaultCountdown { width: 240px; height: 45px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1>jQuery Countdown Basics</h1>

<!--p><strong>25th January</strong> == austDay = new Date(austDay.getFullYear() + 1, 1 - 1, 26);</p-->

<p>What is October 24th at 9am?</p>

<div id="defaultCountdown"></div>

<hr>

<p>&nbsp;</p>

相关问题