【小目标】1st Flag——time.js

第 [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})

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值