momodevtools
Version:
file tools
34 lines (31 loc) • 780 B
JavaScript
/*
* @Author: momokara
* @description: 输入文件说明
*/
const countCostTime = async (fn) => {
const startTime = new Date();
try {
let res = await fn;
const costTime = new Date() - startTime;
return { res, costTime };
} catch (error) {
throw error;
}
};
/**
* 输出格式化的时间
* @param {date} date 需要被格式化的日期
*/
const formatDat = (date) => {
const year = date.getFullYear() + "-";
const month = date.getMonth() + 1 + "-";
const day = date.getDate() + "|";
const hour = date.getHours() + ":";
const min = date.getMinutes() + ":";
const sec = date.getSeconds() + ":";
return `${year + month + day + hour + min + sec}`;
};
module.exports = {
countCostTime,
formatDat,
};