I need to create a countdown script that reads the due date from an XML file,
The XML FILE:
<?xml version="1.0" ?>
<Imskia ID="Ramadan2012">
<day date="2012, 7 - 1, 23">
<Fagr>3:26</Fagr>
<Shrok>5:22</Shrok>
<Dohr>12:02</Dohr>
<Asr>3:38</Asr>
<Maghrb>6:57</Maghrb>
<Ishaa>8:27</Ishaa>
</day>
<day date="2012, 7 - 1, 24">
<Fagr>3:26</Fagr>
<Shrok>5:22</Shrok>
<Dohr>12:02</Dohr>
<Asr>3:38</Asr>
<Maghrb>6:59</Maghrb>
<Ishaa>8:27</Ishaa>
</day>
</Imskia>
and here the Javascipt in the HTML file:
$(document).ready(function(){
$.get('test.xml', function(d){
$(d).find('day').each(function(){
var $day = $(this);
var date = $day.attr("date");
var Maghrb = $day.find('Maghrb').text();
$('body').append($(html));
//countdown
$('#defaultCountdown').countdown({
until: new Date(date), timezone: +2
});
});
});
});
the problem was that the countdown script doesn’t read the variable stores the Date from the XML file, but it works fine when put it manually as below:
//countdown
$('#defaultCountdown').countdown({
until: new Date(2012, 7 - 1, 24), timezone: +2
});
When you do
dateholds a string literal ("2012, 7 - 1, 23"for the first case). What you need to do is to somehow convert this string literal into a JavaScriptDateobject. If you can do without the subtraction in the month component (i.e., keep your date string as"2012, 6, 23", then the simplest way to get the date would beNote that the second argument to
new Date()(the month component) is 0-indexed so January is 0 and December is 11.And you can change the countdown to
However, if changing the format of the date isn’t an option,
evalshould help you convert the subtraction string to its actual value. In this case, the code would be