Javascript Jquery Datetime带有不同Datetime格式的计时器
我想在我的网页中显示当前日期时间,该网页将显示当前日期时间计数器。这意味着它会像c#timer一样增加每秒钟的时间 我为此使用了以下代码Javascript Jquery Datetime带有不同Datetime格式的计时器,javascript,jquery,Javascript,Jquery,我想在我的网页中显示当前日期时间,该网页将显示当前日期时间计数器。这意味着它会像c#timer一样增加每秒钟的时间 我为此使用了以下代码 <label id = "TimerValue" ></label> var test = new Date($.now()); var timer = $.timer(function () { var ttt = moment(++test).format(Tag); $("#Timer
<label id = "TimerValue" ></label>
var test = new Date($.now());
var timer = $.timer(function () {
var ttt = moment(++test).format(Tag);
$("#TimerValue").html(ttt);
});
timer.set({ time: 1000, autostart: true });
定时器我有使用插件
其中矩是格式化日期时间字符串的插件
我也提到,但没有成功
有人能帮我解决这个问题吗?也许这可以帮助您(获取每个值并创建一个字符串,以您正在创建的格式显示时间):
函数updatelock()
{
var currentTime=新日期();
var currentHours=currentTime.getHours();
var currentMinutes=currentTime.getMinutes();
var currentSeconds=currentTime.getSeconds();
//如果需要,用前导零填充分和秒
currentMinutes=(currentMinutes<10?“0”:“)+currentMinutes;
currentSeconds=(currentSeconds<10?“0”:“)+currentSeconds;
//根据需要选择“上午”或“下午”
var timeOfDay=(当前小时数<12)?“AM”:“PM”;
//如果需要,将小时数组件转换为12小时格式
currentHours=(currentHours>12)?currentHours-12:currentHours;
//将小时数分量“0”转换为“12”
当前小时数=(当前小时数==0)?12:当前小时数;
//编写要显示的字符串
var currentTimeString=currentHours+“:”+currentMinutes+“:“+currentSeconds+”+timeOfDay;
$(“#时钟”).html(currentTimeString);
}
$(文档).ready(函数()
{
setInterval('UpdateLock()',1000);
});
yyyy-MM-dd HH:mm:ss
yyyy-MM-dd HH:mm
yyyy/MM/dd HH:mm:ss
yyyy/MM/dd HH:mm
yyyy年MM月dd日 HH時mm分ss秒
yyyy年MM月dd日 HH時mm分
yyyy年MM月dd日
HH時mm分ss秒
HH:mm:ss
HH時mm分
HH:mm
HH時
function updateClock ( )
{
var currentTime = new Date ( );
var currentHours = currentTime.getHours ( );
var currentMinutes = currentTime.getMinutes ( );
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;
$("#clock").html(currentTimeString);
}
$(document).ready(function()
{
setInterval('updateClock()', 1000);
});