当前位置:网站首页>使用day.js让时间 (显示为几分钟前 几小时前 几天前 几个月前 )
使用day.js让时间 (显示为几分钟前 几小时前 几天前 几个月前 )
2022-07-07 11:54:00 【疤痕体】
效果图

代码
utils.ts
通过引入utils.ts
import dayjs from 'dayjs';
import 'dayjs/locale/zh-cn';
import relativeTime from 'dayjs/plugin/relativeTime';
dayjs.extend(relativeTime); // 相对时间
dayjs.locale('zh-cn'); // 使用本地化语言
// 需要安装cnpm i dayjs --save
/* * @param time 时间字符串 * @param friendly 显示xxx时间前 (显示为几分钟前 几小时前 几天前 几个月前 ) */
export function getLastTimeStr(time: string, friendly: boolean) {
if (friendly) {
return dayjs(time).fromNow().replace(' ', '');
}
return dayjs(new Date(time)).format('YYYY-MM-DD HH:mm');
}
main.js
import dayjs from 'dayjs'
app.config.globalProperties.day=dayjs
使用的页面
import {
getLastTimeStr} from '../utils/utils'//引入
setup() {
const data = reactive({
getLastTimeStr(time: string, friendly: boolean) {
return getLastTimeStr(time, friendly);
},
})
}
<div>{
{
getLastTimeStr(item.create_at, true)}}</div>
边栏推荐
- toRaw和markRaw
- 交付效率提升52倍,运营效率提升10倍,看《金融云原生技术实践案例汇编》(附下载)
- User management summary of mongodb
- 带你掌握三层架构(建议收藏)
- Excerpt from "misogyny: female disgust in Japan"
- 如何让join跑得更快?
- 供应链供需预估-[时间序列]
- Shell batch file name (excluding extension) lowercase to uppercase
- 最佳实践 | 用腾讯云AI意愿核身为电话合规保驾护航
- mysql导入文件出现Data truncated for column ‘xxx’ at row 1的原因
猜你喜欢

2022-7-6 初学redis(一)在 Linux 下下载安装并运行 redis

室内ROS机器人导航调试记录(膨胀半径的选取经验)

Digital IC Design SPI

Storage principle inside mongodb

"Song of ice and fire" in the eleventh issue of "open source Roundtable" -- how to balance the natural contradiction between open source and security?

1. Deep copy 2. Call apply bind 3. For of in differences
![供应链供需预估-[时间序列]](/img/2c/82d118cfbcef4498998298dd3844b1.png)
供应链供需预估-[时间序列]

高等數學---第八章多元函數微分學1

118. Yanghui triangle

10 pictures open the door of CPU cache consistency
随机推荐
ROS机器人更换新雷达需要重新配置哪些参数
MySQL error 28 and solution
TPG x AIDU | AI leading talent recruitment plan in progress!
Laravel Form-builder使用
2022-7-6 初学redis(一)在 Linux 下下载安装并运行 redis
LIS longest ascending subsequence problem (dynamic programming, greed + dichotomy)
实现IP地址归属地显示功能、号码归属地查询
Read PG in data warehouse in one article_ stat
566. 重塑矩阵
[dark horse morning post] Huawei refutes rumors about "military master" Chen Chunhua; Hengchi 5 has a pre-sale price of 179000 yuan; Jay Chou's new album MV has played more than 100 million in 3 hours
交付效率提升52倍,运营效率提升10倍,看《金融云原生技术实践案例汇编》(附下载)
My "troublesome" subordinates after 00: not bad for money, against leaders, and resist overtime
Flink | multi stream conversion
Evolution of customer service hotline of dewu
QQ medicine, Tencent ticket
2022-7-6 Leetcode27. Remove the element - I haven't done the problem for a long time. It's such an embarrassing day for double pointers
Oracle advanced (V) schema solution
JS slow motion animation principle teaching (super detail)
Use of polarscatter function in MATLAB
Shell batch file name (excluding extension) lowercase to uppercase