时间格式化展示组件
时间格式化展示组件,支持绝对时间与相对时间。
<uni-time-format :timestamp="Date.now()" format="datetime"></uni-time-format>
format=relative 按自然日输出:
< 1 分钟 输出“刚刚”
< 60 分钟 输出“n分钟前”
>= 60 分钟 输出“n小时前”根据 uni.getAppBaseInfo().appLanguage 自动匹配:
zh)zh-hant / zh-tw / zh-hk / zh-mo)fr)la)法文、拉丁文使用短文案,避免长文本占位。
当 timestamp 非法时,组件返回空字符串。
/pages/uni-ui/time-format/time-format
示例页面包含两组相对时间演示:
yyyy-mm-dd hh:mm:ss,实时展示对应相对时间| Web | 微信小程序 | Android | iOS | HarmonyOS | HarmonyOS(Vapor) |
|---|---|---|---|---|---|
| 4.0 | 4.41 | 3.9 | 4.11 | 4.61 | 5.08 |
| 名称 | 类型 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|
| timestamp | number | - | - | 需要格式化的时间戳,支持秒级(10 位)或毫秒级(13 位),秒级会自动换算成毫秒 |
| format | string | undefined | "datetime" | - | 输出格式。"datetime" 输出 YYYY-MM-DD HH:mm;"date" 输出 YYYY-MM-DD;"time" 输出 HH:mm:ss;"relative" 输出相对时间(刚刚 / N 分钟前 / N 小时前 / 昨天 HH:mm / 完整日期) |