dongyuan1870 2015-12-20 11:50
浏览 64

firefox和IE中的错误日期NaN

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

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 数学建模,尽量用matlab回答,论文格式
    • ¥15 昨天挂载了一下u盘,然后拔了
    • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
    • ¥20 易康econgnition精度验证
    • ¥15 msix packaging tool打包问题
    • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能