Jquery Datetime with timer 具有不同的日期时间格式

Jquery Datetime with timer with diffrent datetime formats

本文关键字:日期 时间 格式 Datetime with timer Jquery      更新时间:2023-09-26

我想在我的网页中显示当前日期时间,这将显示日期时间的当前计数器。意味着它将像 c# 计时器一样增加每秒的时间。

我为此使用了以下代码。

    <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 });

此代码增加值。但格式是">1419227503752";

此值每秒递增。

可能是这个值是正确的,但现在我想将此值更改为我定义的日期时间格式。

部分格式如下:

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);
});

http://www.sitepoint.com/create-jquery-digital-clock-jquery4u/