我有一个奇怪的问题..我有一个用秒计数器显示时间的功能,但是当秒数达到 59 时,我发送了特定时间(小时和分钟)作为参数,没有增加分钟,我不确定小时时是否有同样的问题分钟将是 59 分钟
function updateClock(current_hours,current_minutes) {
var currentTime = new Date ( );
var currentHours = current_hours;
var currentMinutes = current_minutes;
var currentSeconds = currentTime.getSeconds ( );
// Pad the minutes and seconds with leading zeros, if required
currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;
// Choose either "AM" or "PM" as appropriate
var timeOfDay = ( currentHours < 12 ) ? "AM" : "PM";
// Convert the hours component to 12-hour format if needed
currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours;
// Convert an hours component of "0" to "12"
currentHours = ( currentHours == 0 ) ? 12 : currentHours;
// Compose the string for display
var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds + " " + timeOfDay;
// Big font time
$('.big_time').html("<span></span>" + currentTimeString);
// Time in red triangle in the track bar
$('.time').html(currentTimeString);
}
我在准备好的文档中的另一个文件中调用此函数..我将从 API 检索到的数据发送到这里(小时和分钟)
current_hours = data.current_hours;
current_minutes = data.current_minutes;
setInterval(function(){updateClock(current_hours,current_minutes)},1000);