我有开始时间:2015-02-18 20:46:44.213
和歌曲的持续时间:120000
如何获得时间和剩余时间?
编辑:
代码:
$data = simplexml_load_file('http://api.radionomy.com/currentsong.cfm?radiouid=dba94474-bd22-468d-bbe3-cc2c32c3220c&type=xml&cover=yes&callmeback=yes&defaultcover=yes&streamurl=yes&zoneid=0&countrycode=&size=90&dynamicconf=yes&cachbuster=144626');
$currentSong = $data->track;
print_r ( $currentSong );
$song = $currentSong->title . ' - ' . $currentSong->artists;
$startTime = $currentSong->starttime;
$songDuration = $currentSong->playduration;
$dateTime = new DateTime( $startTime );
$timeStampStart = $dateTime->getTimestamp();
$timeNow = time();
$timeElapsed = ($timeStampStart - $timeNow);
$timeLeft = ($songDuration - $timeElapsed);
$ar = array( "song" => $song, "elapsedTime" => $timeElapsed, "timeLeft" => $timeLeft);
print_r ( $ar );
答案 0 :(得分:0)
将该开始时间转换为unix时间戳。
将当前时间作为unix时间戳记。
从当前时间减去开始时间。
这个差异是经过的时间(以毫秒为单位)。
从持续时间中减去。
第二个差异将是剩余时间。