Reputation: 5342
I am using this CountDown Plugin, here is my code and view:
<div class="sc" lang="2013, 12 -1, 18">
<div class="sc" lang="2013, 6 -1, 22">
<script>
$(document).ready(function(){
$(".sc").each(function(){
$(this).countdown({until: $(this).attr("lang"), compact: true, format: 'HMS', description: ''});});});
</script>
My problem is it returns wrong time, example: 00:34:00 and the other is 00:34:03.
Could anyone help me?
I'm trying to learn English, so i speak English not well, so sorry.
Upvotes: 0
Views: 1038
Reputation: 4376
You are using the until parameter incorrectly, you need a new Date object there and your current lang attr cannot be parsed into that.
EDIT: Since your target date is so far away it would be better if you used ODHMS
or DHMS
as your format to include months and days as needed.
I have made some changes to your code to make it work.
HTML:
<div class="sc" lang="2013, 11, 18"></div>
<div class="sc" lang="2013, 5, 22"></div>
JQuery:
$(document).ready(function () {
$("div.sc").each(function (i, item) {
var targetDate = $(item).attr("lang").split(',');
$(item).countdown({
until: new Date(targetDate[0].trim(), targetDate[1].trim(), targetDate[2].trim()),
compact: true,
format: 'DHMS',
description: ''
});
});
});
Also check a working sample in this fiddle: http://jsfiddle.net/EkmsT/
EDIT 2 : I have changed the lang values to 11 and 5 instead of 12-1 and 6-1 and used it directly in the countdown code as targetDate[1].trim(). You can still use 12 -1 and 6 -1 and change the new Date code to use parseInt(targetDate[1].trim())
Upvotes: 2
Reputation: 4136
You have not defined date
function while defining the until
argument in jquery count down. And There is a space between the date in lang
attr.
<div class="sc" lang="2013, 10, 21"></div>
<div class="sc" lang="2013, 5, 23"></div>
<script>
$(document).ready(function(){
$(".sc").each(function(){
var dateSplit = $(this).attr("lang").split(',');alert(dateSplit[0].trim());
var dateRem = new Date(dateSplit[0].trim(), dateSplit[1].trim(), dateSplit[2].trim());
$(this).countdown({until: dateRem, compact: true, format: 'HMS', description: ''});});
});
</script>
Upvotes: 1
Reputation: 27364
well its because timezone is not set.
try this.
$(this).countdown({until: $(this).attr("lang"), compact: true, format: 'HMS', description: '',timezone: +60});
Set timezone accordingly.
Upvotes: 1