/**
* @Memo 时间工具类
*
* @Author songyf
* @Date Aug 22,2019
*
* @Readme 调用方式:eg: $("#id").html(plugin.convertTime("2019-08-23 15:00:00"));
$("#id").html(plugin.convertTime(new Date()));
$("#id").html(plugin.convertTime(new Date("2019-08-21")));
......
*/
;(function(win,undefined) {
"use strict"
var _win;
var plugin = {
/**
* 功能一:转换某个时间距离当前时间的间隔 【刚刚、1分钟前、半个小时前...】
* @param e
* @param t
* @returns
*/
convertTime: function(e , t) {
var i = this,
o = [[], []],
a = (new Date).getTime() - new Date(e).getTime();
return a > 6912e5 ? (a = new Date(e), o[0][0] = i.digit(a.getFullYear(), 4), o[0][1] = i.digit(a.getMonth() + 1), o[0][2] = i.digit(a.getDate()), t || (o[1][0] = i.digit(a.getHours()), o[1][1] = i.digit(a.getMinutes()), o[1][2] = i.digit(a.getSeconds())), o[0].join("-") + " " + o[1].join(":")) : a >= 864e5 ? (a / 1e3 / 60 / 60 / 24 | 0) + "天前": a >= 36e5 ? (a / 1e3 / 60 / 60 | 0) + "小时前": a >= 12e4 ? (a / 1e3 / 60 | 0) + "分钟前": a < 0 ? "未来": "刚刚"
},
digit: function(e, t) {
var i = "";
e = String(e),
t = t || 2;
for (var o = e.length; o < t; o++) i += "0";
return e < Math.pow(10, t) ? i + (0 | e) : e
},
}
//将插件对象暴露给全局对象
_win = (function(){ return this || (0, eval)('this'); }());
!('plugin' in _win) && (_win.plugin = plugin);
}());