Module: date

本模块提供日期处理相关方法。
Source:

Methods

(static) formatDate(date, formation) → {string}

格式化日期。
Parameters:
Name Type Description
date Date | number 日期对象或时间戳(毫秒)。
formation string 格式。
Author:
  • luoliquan
Source:
Returns:
格式化结果。
Type
string
Example
formatDate(new Date(2018, 9, 8, 8, 50, 56), 'YYYY-MM-DD hh:mm:ss'); // '2018-10-08 08:50:56'

(static) formatSeconds(secs, optionsopt) → {string}

把秒数格式化成「时:分:秒」格式。
Parameters:
Name Type Attributes Description
secs number 秒数。
options Object <optional>
格式化配置。
Properties
Name Type Attributes Default Description
segments number <optional>
2 段数,2 或者 3。 为 2 时,如果小时为 0,则格式化样式为「分:秒」。
digits number <optional>
2 每一段数字的最小位数,不足位数时补 0。
Author:
  • luoliquan
Source:
Returns:
格式化结果。
Type
string
Example
formatSeconds(3682); // '01:01:22'
formatSeconds(82); // '01:22'
formatSeconds(82, { segments: 3 }); // '00:01:22'
formatSeconds(3682, { digits: 1 }); // '1:1:22'