前端 時間個人化 外掛程式 jquery.timeago.js

來源:互聯網
上載者:User

標籤:

關鍵詞 :

時間格式化 剛剛 N分鐘前 N小時前 N天前 N月前 N年前 

MM-dd hh:mm  或者  yyyy-MM-dd

 

前端: 

<span class="time" title="2016-07-23 12:02:32"></span>

  

 

用法:

 $(".time").timeago();

 

外掛程式: jquery.timeago.js

 

!function (t) {    function e(e) {        var n = t.extend(o.settings, e)          , s = t.proxy(r, this);        s(),        n.refreshMillis > 0 && setInterval(s, n.refreshMillis)    }    function r() {        var e = n(this)          , r = e.datetime;        return isNaN(r) || t(this).text(o.inWords(r)),        this    }    function n(e) {        return e = t(e),        e.data("timeago") || e.data("timeago", {            datetime: o.datetime(e)        }),        e.data("timeago")    }    function s(t) {        return (new Date).getTime() - t.getTime()    }    function i(t) {        var e = new Date;        return e.getMonth() > t.getMonth() || e.getDate() > t.getDate()    }    function a(t) {        return (new Date).getFullYear() > t.getFullYear()    }    Date.prototype.format = function (t) {        var e = {            "M+": this.getMonth() + 1,            "d+": this.getDate(),            "h+": this.getHours(),            "m+": this.getMinutes(),            "s+": this.getSeconds(),            "q+": Math.floor((this.getMonth() + 3) / 3),            S: this.getMilliseconds()        };        /(y+)/.test(t) && (t = t.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)));        for (var r in e)            new RegExp("(" + r + ")").test(t) && (t = t.replace(RegExp.$1, 1 == RegExp.$1.length ? e[r] : ("00" + e[r]).substr(("" + e[r]).length)));        return t    }    ;    var o = {        settings: {            refreshMillis: 6e4,            relative: !0,            strings: {                suffixAgo: "前",                seconds: "剛剛",                minute: "1分鐘",                minutes: "%d分鐘",                hour: "1小時",                hours: "%d小時",                days: "%d天",                months: "%d月",                years: "%d年",                numbers: []            },            yearsAgoFormat: "yyyy-MM-dd",            daysAgoFormat: "MM-dd hh:mm"        },        inWords: function (e) {            function r(e, r) {                var n = t.isFunction(e) ? e(r, u) : e                  , s = g.numbers && g.numbers[r] || r;                return n.replace(/%d/i, s)            }            var n = o.settings.relative;            if (!n && a(e))                return e.format(this.settings.yearsAgoFormat);            if (!n && i(e))                return e.format(this.settings.daysAgoFormat);            var u = s(e)              , g = this.settings.strings              , h = g.suffixAgo              , d = Math.abs(u) / 1e3              , l = d / 60              , f = l / 60              , m = f / 24              , c = m / 30              , M = m / 365;            return words = 60 > d ? r(g.seconds, Math.floor(d)) : 60 > l ? r(g.minutes, Math.floor(l)) : 24 > f ? r(g.hours, Math.floor(f)) : 30 > m ? r(g.days, Math.floor(m)) : 365 > m ? r(g.months, Math.floor(c)) : r(g.years, Math.floor(M)),            "剛剛" == words ? words : words + h        },        parse: function (e) {            var r = t.trim(e);            return r = r.replace(/\.\d+/, ""),            r = r.replace(/-/, "/").replace(/-/, "/"),            r = r.replace(/T/, " ").replace(/Z/, " UTC"),            r = r.replace(/([\+\-]\d\d)\:?(\d\d)/, " $1$2"),            new Date(r)        },        datetime: function (e) {            var r = t(e).attr(o.isTime(e) ? "datetime" : "title");            return o.parse(r)        },        isTime: function (e) {            return "time" === t(e).get(0).tagName.toLowerCase()        }    };    t.fn.timeago = function (t) {        return this.each(function () {            e.call(this, t)        }),        this    }}(window.jQuery)

 

前端 時間個人化 外掛程式 jquery.timeago.js

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.