| | |
| | | import { isObject, isString } from '/@/utils/is'; |
| | | import moment from 'moment'; |
| | | |
| | | const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm'; |
| | | const DATE_FORMAT = 'YYYY-MM-DD '; |
| | | |
| | | export function formatToDateTime(date: moment.MomentInput = null): string { |
| | | return moment(date).format(DATE_TIME_FORMAT); |
| | | export function formatToDateTime( |
| | | date: moment.MomentInput = null, |
| | | format = DATE_TIME_FORMAT |
| | | ): string { |
| | | return moment(date).format(format); |
| | | } |
| | | |
| | | export function formatToDate(date: moment.MomentInput = null): string { |
| | | return moment(date).format(DATE_FORMAT); |
| | | export function formatToDate(date: moment.MomentInput = null, format = DATE_FORMAT): string { |
| | | return moment(date).format(format); |
| | | } |
| | | |
| | | export const formatAgo = (str: string | number) => { |
| | |
| | | return parseInt(String(time / 31536000000)) + '年前'; |
| | | } |
| | | }; |
| | | /** |
| | | * @description: 格式化请求参数时间 |
| | | */ |
| | | export function formatRequestDate(params: any) { |
| | | for (const key in params) { |
| | | if (params[key] && params[key]._isAMomentObject) { |
| | | params[key] = params[key].format(DATE_TIME_FORMAT); |
| | | } |
| | | if (isString(key)) { |
| | | const value = params[key]; |
| | | if (value) { |
| | | try { |
| | | params[key] = isString(value) ? value.trim() : value; |
| | | } catch (error) { |
| | | throw new Error(error); |
| | | } |
| | | } |
| | | } |
| | | if (isObject(params[key])) { |
| | | formatRequestDate(params[key]); |
| | | } |
| | | } |
| | | } |
| | | |
| | | export const dateUtil = moment; |