

/**
 * UTC时间字符串转为北京时间
 * @param {*} utcStr 2025-05-15T02:16:27.000+00:00
 * @returns 2025-05-15 10:16:27
 */
export function convertUTCToBeijing(utcStr) {
    if (utcStr) {
        const date = new Date(utcStr);

        // 北京时间 = UTC 时间
        date.setHours(date.getHours());

        const pad = (n) => String(n).padStart(2, '0');
        const y = date.getFullYear();
        const m = pad(date.getMonth() + 1);
        const d = pad(date.getDate());
        const hh = pad(date.getHours());
        const mm = pad(date.getMinutes());
        const ss = pad(date.getSeconds());

        return `${y}-${m}-${d} ${hh}:${mm}:${ss}`;
    } else {
        return utcStr
    }
}

/**
 * 转成小写字符
 * userStatus 转成 user_status
 * @param {*} str 
 * @returns 
 */
export function camelToSnake(str) {
    return str.replace(/([A-Z])/g, '_$1').toLowerCase();
}