第 [1] 个js代码项目
time.js
/*!
* Time JavaScript Library v1.4.5
* Author: Chi Zeyu.
* Date: 2022-12-20T21:28Z
*/
;( function( global, factory ) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
global.time = factory;
} ( typeof window !== "undefined" ? window : this, function (config) {
if (typeof config === "object") {
if (config.type == "time") { //time
function formatDate(format) {
date = new Date();
const that = new Date(date);
var table = { // create timetable
'M+': that.getMonth() + 1, // months
'd+': that.getDate(), // dates
'h+': that.getHours(), // hours
'm+': that.getMinutes(), // minutes
's+': that.getSeconds(), // seconds
'S+': that.getMilliSeconds(),//milliseconds
};
if (/(y+)/.test(format)) { //regex
format = format.replace(RegExp.$1, (that.getFullYear() + '')
.substr(4 - RegExp.$1.length));
}
for (var str in table) {
if (new RegExp('(' + str + ')')
.test(format)) {
format = format.replace(RegExp.$1, (RegExp.$1.length === 1) ? (table[str]) : (('00' + table[str])
.substr(('' + table[str])
.length))); //replace
}
}
return format;
}
return formatDate(config.format)
} else if (config.type == "timestamp") { //timestamp
return new Date()
.getTime();
}
} else {
throw new Error("Param 'config' is not an object"); //error
}
} ))
time.min.js
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.time=t}("undefined"!=typeof window?window:this,function(e){function t(e){date=new Date
const t=new Date(date)
var n={"M+":t.getMonth()+1,"d+":t.getDate(),"h+":t.getHours(),"m+":t.getMinutes(),"s+":t.getSeconds(),"S+":t.getMilliSeconds()};/(y+)/.test(e)&&(e=e.replace(RegExp.$1,(t.getFullYear()+"").substr(4-RegExp.$1.length)))
for(var o in n)RegExp("("+o+")").test(e)&&(e=e.replace(RegExp.$1,1===RegExp.$1.length?n[o]:("00"+n[o]).substr((""+n[o]).length)))
return e}if("object"!=typeof e)throw Error("Param 'config' is not an object")
return"time"==e.type?t(e.format):"timestamp"==e.type?(new Date).getTime():void 0})