UNPKG

mihawk

Version:

A tiny & simple mock server tool, support json,js,cjs,ts(typescript).

28 lines (27 loc) 1.07 kB
/** * 日期格式化,格式为 yyyy-mm-dd_hh:mm:ss.ms * @param {Date} date * @returns {string} * @example * const now = new Date(); * console.log(dateFormat(now)); // 默认格式: yyyy-MM-dd hh:mm:ss, eg: 2025-05-03 04:25:41 * console.log(dateFormat(now, 'yyyy年MM月dd日 HH:mm:ss')); // 24小时制, eg: 2025年05月03日 04:25:41 * console.log(dateFormat(now, 'yy-M-d h:m:s a')); // 12小时制带AM/PM, eg: 25-5-3 4:25:41 AM * console.log(dateFormat(now, 'yyyy-MM-dd HH:mm:ss.SSS')); // 带毫秒, eg: 2025-05-03 04:25:41.661 */ export declare function dateFormat(date: Date, fmt?: string): string; /** * 获取当前时间字符串,格式为 yyyy-mm-dd_hh:mm:ss.ms * @returns {string} */ export declare function getTimeNowStr(): string; /** * 宽松型日期数据表示 */ export type LooseDate = Date | string | number; /** * 确保返回一个 Date 数据,可接受兼容 string 和 Date 格式 * @param {Date | string | number} dt * @returns {Date} */ export declare function ensureDate(dt: LooseDate, noCheck?: boolean): Date;