当前位置:网站首页>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>
边栏推荐
- DID登陆-MetaMask
- 现在网上开户安全么?那么网上开户选哪个证券公司?
- 648. 单词替换 : 字典树的经典运用
- Realize the IP address home display function and number home query
- 2022-7-7 Leetcode 844. Compare strings with backspace
- 566. Reshaping the matrix
- AI人才培育新思路,这场直播有你关心的
- call undefined function openssl_ cipher_ iv_ length
- 内存溢出和内存泄漏的区别
- LeetCode_ Binary search_ Medium_ 153. Find the minimum value in the rotation sort array
猜你喜欢

566. Reshaping the matrix

Xshell connection server changes key login to password login

LIS longest ascending subsequence problem (dynamic programming, greed + dichotomy)

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

得物客服热线的演进之路
![SSRF vulnerability file pseudo protocol [netding Cup 2018] fakebook1](/img/10/6de1ee8467b18ae03894a8d5ba95ff.png)
SSRF vulnerability file pseudo protocol [netding Cup 2018] fakebook1

Indoor ROS robot navigation commissioning record (experience in selecting expansion radius)

Co create a collaborative ecosystem of software and hardware: the "Joint submission" of graphcore IPU and Baidu PaddlePaddle appeared in mlperf

Build a secure and trusted computing platform based on Kunpeng's native security

为租客提供帮助
随机推荐
Redis只能做缓存?太out了!
PHP - laravel cache
Excerpt from "misogyny: female disgust in Japan"
10 pictures open the door of CPU cache consistency
Server to server (S2S) event (adjust)
Build a secure and trusted computing platform based on Kunpeng's native security
2022-7-6 beginner redis (I) download, install and run redis under Linux
AI人才培育新思路,这场直播有你关心的
LeetCode_二分搜索_中等_153.寻找旋转排序数组中的最小值
Milkdown control icon
xshell连接服务器把密钥登陆改为密码登陆
My "troublesome" subordinates after 00: not bad for money, against leaders, and resist overtime
requires php ~7.1 -&gt; your PHP version (7.0.18) does not satisfy that requirement
Shell batch file name (excluding extension) lowercase to uppercase
[1] Basic knowledge of ros2 - summary version of operation commands
干货|总结那些漏洞工具的联动使用
Advanced Mathematics - Chapter 8 differential calculus of multivariate functions 1
Help tenants
Ways to improve the performance of raspberry pie
DID登陆-MetaMask