UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

79 lines (78 loc) 2.3 kB
/** * 功能和上面的dateFormat/timeStampFormat类型,只是参数time可以接收多种类型,且参数cFormat用的是{y}形式 * @param {(Object|string|number)} time 输入日期 * @param {string} cFormat 时间格式 * @returns {string | null} 格式化后的日期字符串 * @example * * const date = new Date('2020-11-27 8:23:24'); * * const res = parseTime(date, 'yyyy-MM-dd hh:mm:ss') * * // 2020-11-27 08:23:24 */ export declare function parseTime(time: Date | number, cFormat: string): string | null; /** * 获取某个时间戳距离今天的时间 * @param {number} timestamp * @returns {string} 距离今天的时间描述 * @example * * const date = new Date('2020-11-27 8:23:24').getTime(); * getTimeAgo(date); * // 1个月前 * * const date2 = new Date('2021-11-27 8:23:24').getTime(); * getTimeAgo(date2); * // 10个月后 */ export declare function getTimeAgo(timestamp: number): string; /** * 功能:获取多久之前,若间隔超过一天,返回时刻描述 * @param {number} timestamp 时间戳 * @param {string} format 时间格式 * @returns {string} 距离今天的时间描述或者时刻描述 * @example * * getTimeAgoOrDate(Date.now() - 60 * 60 * 24 * 1 * 1000); * // 1天前 * * const date = new Date('2018-07-13 17:54:01').getTime(); * getTimeAgoOrDate(date); * // 7月13日17时54分 */ export declare function getTimeAgoOrDate(time: string | number, format: string): string | null; /** * 倒计时(eg:距开赛1天) * @param {string} time 剩余时间 * @param {SECOND | MINUTE | HOUR | DAY } [maxUnit] 最大单位 * @returns {object} 剩余时间的描述对象 * @example * * getCountDownObj(100) * // { day: 0, hour: 0, minute: 1, second: 40 } * * getCountDownObj(1*24*60*60+200) * // { day: 1, hour: 0, minute: 3, second: 20 } * * getCountDownObj(1 * 24 * 60 * 60 + 2 * 60 * 60 + 1 * 60 + 11, 'HOUR') * // 结果 => * { * fHour: '26', * fMinute: '01', * fSecond: '11', * hour: 26, * minute: 1, * second: 11, * } */ export declare function getCountDownObj(time: number | string, maxUnit?: string): { day?: Number; hour?: Number; minute?: Number; second?: Number; fDay?: String; fHour?: String; fMinute?: String; fSecond?: String; };