jquery从时间戳中获取时间

时间:2016-04-07 22:31:18

标签: javascript jquery datetime date-format

我试图在格式为“2012-10-10T06:42:47Z”的时间戳上以太平洋标准时间晚上10点30分格式显示我的观看时间。我尝试了不同的方法来做到这一点并失败了。有什么好的选择以这种格式显示时间吗?

My trail is here

$(document).ready(function() {
 $("span.localtime").localtime();
});

(function() {
  (function($) {
    return $.fn.localtime = function() {
      var fmtDate, fmtZero;
      fmtZero = function(str) {
        return ('0' + str).slice(-2);
      };
      fmtDate = function(d) {
        var hour, meridiem;
        hour = d.getHours();
        if (hour < 12) {
          meridiem = "AM";
        } else {
          meridiem = "PM";
        }
        if (hour === 0) { hour = 12; }
        if (hour > 12) { hour = hour - 12; }
        return hour + ":" + fmtZero(d.getMinutes()) + " " + meridiem + " " + (d.getMonth() + 1) + "/" + d.getDate() + "/" + d.getFullYear();
      };
      return this.each(function() {
        var tagText;
        tagText = $(this).html();
        $(this).html(fmtDate(new Date(tagText)));
        return $(this).attr("title", tagText);
      });
    };
  })(jQuery);
}).call(this);

0 个答案:

没有答案
相关问题