UNPKG

@hanyanpeng/data-utilities

Version:

js工具包

44 lines (38 loc) 945 B
'use strict'; const arrayPush = (arr, ...args) => { return [...arr, ...args]; }; const arrayJoin = (arr, ch) => { return arr.join(ch); }; const concatStrings = (str1, str2) => { return str1 + str2; }; // 日期格式化功能 const formatDate = (date, format) => { const options = {}; if (format.includes("YYYY")) { options.year = "numeric"; } if (format.includes("MM")) { options.month = "2-digit"; } if (format.includes("DD")) { options.day = "2-digit"; } if (format.includes("hh")) { options.hour = "2-digit"; options.hour12 = false; // 使用24小时制 } if (format.includes("mm")) { options.minute = "2-digit"; } if (format.includes("ss")) { options.second = "2-digit"; } return new Intl.DateTimeFormat("zh-CN", options).format(date); }; exports.arrayJoin = arrayJoin; exports.arrayPush = arrayPush; exports.concatStrings = concatStrings; exports.formatDate = formatDate;