当前位置:网站首页>使用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>
边栏推荐
- 如何让join跑得更快?
- Toraw and markraw
- MySQL error 28 and solution
- [fortress machine] what is the difference between cloud fortress machine and ordinary fortress machine?
- What parameters need to be reconfigured to replace the new radar of ROS robot
- 得物客服热线的演进之路
- [QNX hypervisor 2.2 user manual]6.3.4 virtual register (guest_shm.h)
- Scripy tutorial classic practice [New Concept English]
- 1、深拷贝 2、call apply bind 3、for of for in 区别
- "Song of ice and fire" in the eleventh issue of "open source Roundtable" -- how to balance the natural contradiction between open source and security?
猜你喜欢
Detr introduction
How to make join run faster?
室內ROS機器人導航調試記錄(膨脹半徑的選取經驗)
室内ROS机器人导航调试记录(膨胀半径的选取经验)
Help tenants
Social responsibility · value co creation, Zhongguancun network security and Information Industry Alliance dialogue, wechat entrepreneur Haitai Fangyuan, chairman Mr. Jiang Haizhou
数字ic设计——SPI
C语言数组相关问题深度理解
Error lnk2019: unresolved external symbol
Ways to improve the performance of raspberry pie
随机推荐
Error lnk2019: unresolved external symbol
[1] Basic knowledge of ros2 - summary version of operation commands
SSRF漏洞file伪协议之[网鼎杯 2018]Fakebook1
mysql ”Invalid use of null value“ 解决方法
Write it down once Net a new energy system thread surge analysis
数字ic设计——SPI
Simple and easy-to-use code specification
Evolution of customer service hotline of dewu
Clion mingw64 Chinese garbled code
PC端页面如何调用QQ进行在线聊天?
clion mingw64中文乱码
How to make join run faster?
干货|总结那些漏洞工具的联动使用
带你掌握三层架构(建议收藏)
Flink | multi stream conversion
交付效率提升52倍,运营效率提升10倍,看《金融云原生技术实践案例汇编》(附下载)
记一次 .NET 某新能源系统 线程疯涨 分析
Help tenants
Build a secure and trusted computing platform based on Kunpeng's native security
[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