formatMillisecondsTime: function(milliseconds, formatStr) {
// 创建一个新的Date对象,传入毫秒值
const date = new Date(milliseconds);
// 获取年月日时分秒,并确保它们都是两位数
const year = date.getFullYear();
const month = (date.getMonth() + 1).toString().padStart(2, '0');
const day = date.getDate().toString().padStart(2, '0');
const hours = date.getHours().toString().padStart(2, '0');
const minutes = date.getMinutes().toString().padStart(2, '0');
const seconds = date.getSeconds().toString().padStart(2, '0');
const millis = date.getMilliseconds().toString().padStart(3, '0');
var formatArr = [year, month, day, hours, minutes, seconds, millis]
// console.log(formatArr)
if (!formatStr) {
formatStr = "y-m-d h:i"
}
let formatPure = formatStr.replaceAll('-', '').replaceAll('/', '').replaceAll(':', '').replaceAll(' ',
'')
for (var i = 0; i < formatPure.length; i++) {
formatStr = formatStr.replace(formatPure.charAt(i), formatArr[i]);
}
return formatStr;
},
rgbToHex: function(r, g, b) {
return "#" + utils.toHex(r) + utils.toHex(g) + utils.toHex(b)
},
toHex: function(n) {
n = parseInt(n, 10);
if (isNaN(n)) return "00";
n = Math.max(0, Math.min(n, 255));
return "0123456789ABCDEF".charAt((n - n % 16) / 16) +
"0123456789ABCDEF".charAt(n % 16);
},
hexToRgb(hex) {
let result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16)
} : null;
},
工具类方法