当前位置:网站首页>Use day JS let time (displayed as minutes, hours, days, months, and so on)
Use day JS let time (displayed as minutes, hours, days, months, and so on)
2022-07-07 13:55:00 【Scarring body】
design sketch

Code
utils.ts
By introducing utils.ts
import dayjs from 'dayjs';
import 'dayjs/locale/zh-cn';
import relativeTime from 'dayjs/plugin/relativeTime';
dayjs.extend(relativeTime); // Relative time
dayjs.locale('zh-cn'); // Use localized languages
// Need to install cnpm i dayjs --save
/* * @param time Time string * @param friendly Show xxx Time ago ( Displayed as a few minutes ago A few hours ago A few days ago A few months ago ) */
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
Pages used
import {
getLastTimeStr} from '../utils/utils'// introduce
setup() {
const data = reactive({
getLastTimeStr(time: string, friendly: boolean) {
return getLastTimeStr(time, friendly);
},
})
}
<div>{
{
getLastTimeStr(item.create_at, true)}}</div>
边栏推荐
- toRaw和markRaw
- Esp32 ① compilation environment
- Getting started with MySQL
- Data refresh of recyclerview
- SSRF漏洞file伪协议之[网鼎杯 2018]Fakebook1
- TPG x AIDU | AI leading talent recruitment plan in progress!
- 室內ROS機器人導航調試記錄(膨脹半徑的選取經驗)
- MySQL "invalid use of null value" solution
- What parameters need to be reconfigured to replace the new radar of ROS robot
- mysql导入文件出现Data truncated for column ‘xxx’ at row 1的原因
猜你喜欢

2022-7-6 beginner redis (I) download, install and run redis under Linux

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

交付效率提升52倍,运营效率提升10倍,看《金融云原生技术实践案例汇编》(附下载)

Redis 核心数据结构 & Redis 6 新特性详

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

Fast development board pinctrl and GPIO subsystem experiment for itop-imx6ull - modify the device tree file

10 pictures open the door of CPU cache consistency

Centso7 OpenSSL error Verify return code: 20 (unable to get local issuer certificate)

为租客提供帮助

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
随机推荐
参数关键字Final,Flags,Internal,映射关键字Internal
使用day.js让时间 (显示为几分钟前 几小时前 几天前 几个月前 )
LIS longest ascending subsequence problem (dynamic programming, greed + dichotomy)
toRaw和markRaw
[fortress machine] what is the difference between cloud fortress machine and ordinary fortress machine?
LeetCode_ Binary search_ Medium_ 153. Find the minimum value in the rotation sort array
Split screen bug notes
The delivery efficiency is increased by 52 times, and the operation efficiency is increased by 10 times. See the compilation of practical cases of financial cloud native technology (with download)
My "troublesome" subordinates after 00: not bad for money, against leaders, and resist overtime
Excellent open source system recommendation of ThinkPHP framework
flask session伪造之hctf admin
High end for 8 years, how is Yadi now?
1、深拷贝 2、call apply bind 3、for of for in 区别
干货|总结那些漏洞工具的联动使用
Realize the IP address home display function and number home query
118. 杨辉三角
AI人才培育新思路,这场直播有你关心的
请问指南针股票软件可靠吗?交易股票安全吗?
2022-7-6 sigurg is used to receive external data. I don't know why it can't be printed out
华为镜像地址