我有一个工作脚本,从指定的日期开始每秒计算一次。时间。谁能告诉我如何添加一个逗号,所以它看起来像是:81,547,546
var START_DATE = new Date("October 10, 2012 22:30:00");
var INTERVAL = 1;
var INCREMENT = 1;
var START_VALUE = 35001;
var count = 0;
$(document).ready(function() {
var msInterval = INTERVAL * 1000;
var now = new Date();
count = parseInt((now - START_DATE)/msInterval) * INCREMENT + START_VALUE;
document.getElementById('counter').innerHTML = count;
window.setInterval( function(){
count += INCREMENT;
document.getElementById('counter').innerHTML = count;
}, msInterval);
});
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<div id="counter"></div>
答案 0 :(得分:0)
$url = 'https://www.googleapis.com/youtube/v3/channels?part=id&forUsername=ferrariworld&key=ZZZZZZZZ';
$json = json_decode(file_get_contents($url), true);
foreach ($json as $item){
echo $item[0]['id'];
echo $item[0]['title'];
}
var START_DATE = new Date("October 10, 2012 22:30:00");
var INTERVAL = 1;
var INCREMENT = 1;
var START_VALUE = 35001;
var count = 0;
$(document).ready(function() {
var msInterval = INTERVAL * 1000;
var now = new Date();
count = parseInt((now - START_DATE)/msInterval) + START_VALUE;
document.getElementById('counter').innerHTML = count;
window.setInterval( function(){
count = parseFloat(count.toString().replace(/,/g, ''));
count++;
count = count.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
document.getElementById('counter').innerHTML = count;
}, msInterval);
});