Hello I need to spend a given XML through javascript to subtract the current date and time date.
What makes this code is to show the remaining time of a song streaming in minutes and seconds
And then with javascript parsing date and I transform in milliseconds and the current date will also rest in ms.
In Chrome date shows me perfectly, but in Mozilla and IE NaN console shows me and gives error. I do not understand is that if I have parsed the date because it only works in Chrome. There must be a mistake.
PHP (I draw the start date of a song)
<?php $xml = @ simplexml_load_file('http://www.example.com'); foreach ($xml as $track){ $startTime = $track->starttime; $songDuration = $track->playduration; } ?> JAVASCRIPT: var spend javascript
var tiempoComienzo= "<?php echo $startTime ?>"; var cancionDuracion="<?php echo $songDuration ?>"; //parse delivered date from php var d = new Date(Date.parse(tiempoComienzo)); //PHP get the date in milliseconds var resultPHPms = d.getTime(); //get the current date var f = new Date(); //step the current date to milliseconds var resultJSms = f.getTime(); //adding the date of the song to the length of the song var inicioMasCancion=parseInt(cancionDuracion) + parseInt(resultPHPms); //It is the challenge to the current date var TiempoRestante=inicioMasCancion-parseInt(resultJSms); //pass the result to seconds seconds=(TiempoRestante/1000) var container = document.getElementById('time'); var seconds = parseInt(seconds+7); //step seconds to minutes and seconds var minutes = parseInt( seconds / 60 ) % 60; var seconds = seconds % 60; var contadorDeTiempo=(minutes < 10 ? "0" + minutes : minutes) + ":" + (seconds < 10 ? "0" + seconds : seconds); countdown(seconds); function countdown:
<script> var timer; function countdown(seconds) { seconds--; if(seconds >= -1) { container.innerHTML =contadorDeTiempo; } } timer = setInterval(countdown, 1000); </script> HTML:
<span id='time'></span> In chrome it is perfectly displayed and works perfect. But in Mozilla and IE console NaN it is shown, specifically in this line:
var d = new Date(Date.parse(tiempoComienzo)); How I could solve? The resulting XML date is as follows:
2015-12-20 12:45:33.17 thanks very much for your help
No comments:
Post a Comment