// 转换时间 import { dataTool } from "echarts/lib/echarts"; const conversionTime = { stampToDate: (timestamp) => { var date = new Date(timestamp * 1000); var Y = date.getFullYear() + '-'; var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'; var D = date.getDate() + ' '; var h = date.getHours() + ':'; var m = date.getMinutes() + ':'; var s = date.getSeconds(); return Y + M + D; }, // s转换 stampToSeconds: (timestamp) => { var date = new Date(timestamp * 1000); var Y = date.getFullYear() + '-'; var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'; var D = date.getDate() + ' '; var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':'; var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':'; var s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()); var newdate = Y + M + D + h + m + s; return Y + M + D + h + m + s; }, // ms转换 stampTomsSeconds: (timestamp) => { var date = new Date(timestamp); var Y = date.getFullYear() + '-'; var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'; var D = date.getDate() + ' '; var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':'; var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':'; var s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()); var newdate = Y + M + D + h + m + s; return Y + M + D + h + m + s; }, toMem: (v) => { let mem = (v / 1000 / 1000).toFixed(2); // return `${mem} M`; return `${mem} `; }, toCpu: (v) => { let cpu = (v * 1000).toFixed(2); return `${cpu} `; }, date: (v) => { const date = Date(v * 1000).toLocaleString('zh'); return date; }, humanizeDuration: (duration, fix = 1) => { if (duration === 0) { return '0'; } if (duration < MINUTE) { return this.toInteger(duration / SECOND, fix) + ' 秒'; } if (duration < HOUR) { return this.toInteger(duration / MINUTE, fix) + ' 分'; } if (duration < DAY) { return this.toInteger(duration / HOUR, fix) + '小时'; } return this.toInteger(duration / HOUR / 24, fix) + ' 天'; }, toInteger: (number, fix = 1) => { if (Math.round(number) === number) { return number; } return Number(number).toFixed(fix); }, toIntNum: (v) => { for(let i = 0; i < v.length; i++) { v[i] = parseInt(v[i]); } return v; }, }; export default conversionTime;