DateTimeFormatter 时间格式化器
September 19, 2025 · View on GitHub
DateTimeFormatter 时间格式化器
DateTimeFormatter 是一个继承自 Enum 的时间格式化器类,提供了预定义的时间格式化模板。
预定义格式
FULL_DATE_TIME: 'YYYY-MM-DD HH:mm:ss' - 完整日期时间格式TIMESTAMP: 'x' - 毫秒时间戳格式SHORT_DATE_TIME: 'MM-DD HH:mm' - 短日期时间格式FULL_DATE: 'YYYY-MM-DD' - 完整日期格式FULL_TIME: 'HH:mm:ss' - 完整时间格式YEAR: 'YYYY' - 年份格式MONTH: 'MM' - 月份格式DAY: 'DD' - 日期格式HOUR: 'HH' - 小时格式MINUTE: 'mm' - 分钟格式SECOND: 'ss' - 秒格式
实例方法
formatMilliSecond(milliSecond)
使用这个模板格式化毫秒时间戳
参数:
milliSecond(number): 毫秒时间戳
返回值:
- (string): 格式化后的时间字符串
formatSecond(second)
使用这个模板格式化秒时间戳
参数:
second(number): 秒时间戳
返回值:
- (string): 格式化后的时间字符串
formatDate(date)
使用这个模板格式化日期
参数:
date(Date): 日期对象
返回值:
- (string): 格式化后的时间字符串
format()
使用这个模板格式化当前时间
返回值:
- (string): 格式化后的时间字符串