Commit ebbb6725 by 杨铁龙

优化时间格式化

parent 512a7138
Showing with 6 additions and 4 deletions
...@@ -156,13 +156,15 @@ function formatTime2ShortYearMonthDate(time: Date) { ...@@ -156,13 +156,15 @@ function formatTime2ShortYearMonthDate(time: Date) {
* @param option { rule: 选择是12小时制还是24小时制,short:是否以短时间形式显示 } * @param option { rule: 选择是12小时制还是24小时制,short:是否以短时间形式显示 }
*/ */
export function formatTime( export function formatTime(
time: number, time: number | string,
option = { rule: TimeFormatRule.Hour12, short: false } option = { rule: TimeFormatRule.Hour12, short: false }
) { ) {
if (time < STANDARD) { if (String(time).indexOf("-")) {
time *= 1000; time = String(time).replace(/-/g, "/");
}
if (/^\d+$/.test(time + '') && +time < STANDARD) {
time = +time * 1000;
} }
const t = new Date(time); const t = new Date(time);
const now = new Date(); const now = new Date();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment