当前位置:网站首页>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>
边栏推荐
- 【面试高频题】难度 2.5/5,简单结合 DFS 的 Trie 模板级运用题
- 接口自动化测试-接口间数据依赖问题解决
- 10 pictures open the door of CPU cache consistency
- 供应链供需预估-[时间序列]
- Centso7 OpenSSL error Verify return code: 20 (unable to get local issuer certificate)
- 为租客提供帮助
- Error lnk2019: unresolved external symbol
- 2022-7-6 beginner redis (I) download, install and run redis under Linux
- My "troublesome" subordinates after 00: not bad for money, against leaders, and resist overtime
- 干货|总结那些漏洞工具的联动使用
猜你喜欢

Leecode3. Longest substring without repeated characters

高等数学---第八章多元函数微分学1

Flink | multi stream conversion

Advanced Mathematics - Chapter 8 differential calculus of multivariate functions 1

Mathématiques avancées - - chapitre 8 différenciation des fonctions multivariables 1

My "troublesome" subordinates after 00: not bad for money, against leaders, and resist overtime

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

2022-7-7 Leetcode 34. Find the first and last positions of elements in a sorted array

Xshell connection server changes key login to password login
![供应链供需预估-[时间序列]](/img/2c/82d118cfbcef4498998298dd3844b1.png)
供应链供需预估-[时间序列]
随机推荐
室内ROS机器人导航调试记录(膨胀半径的选取经验)
Laravel Form-builder使用
MySQL error 28 and solution
Laravel5 call to undefined function openssl cipher iv length() 报错 PHP7开启OpenSSL扩展失败
Problems that cannot be accessed in MySQL LAN
Drawerlayout suppress sideslip display
交付效率提升52倍,运营效率提升10倍,看《金融云原生技术实践案例汇编》(附下载)
The reason why data truncated for column 'xxx' at row 1 appears in the MySQL import file
LeetCode_ Binary search_ Medium_ 153. Find the minimum value in the rotation sort array
PostgreSQL array type, each splice
SSRF vulnerability file pseudo protocol [netding Cup 2018] fakebook1
call undefined function openssl_cipher_iv_length
[1] Basic knowledge of ros2 - summary version of operation commands
1. Deep copy 2. Call apply bind 3. For of in differences
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)
3D Detection: 3D Box和点云 快速可视化
flask session伪造之hctf admin
Oracle advanced (V) schema solution
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
带你掌握三层架构(建议收藏)