当前位置:网站首页>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>
边栏推荐
- What are the principles for distinguishing the security objectives and implementation methods that cloud computing security expansion requires to focus on?
- How far can it go to adopt a cow by selling the concept to the market?
- [fortress machine] what is the difference between cloud fortress machine and ordinary fortress machine?
- LIS longest ascending subsequence problem (dynamic programming, greed + dichotomy)
- What parameters need to be reconfigured to replace the new radar of ROS robot
- 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)
- 648. Word replacement: the classic application of dictionary tree
- Attribute keywords aliases, calculated, cardinality, ClientName
- Laravel form builder uses
- Leecode3. Longest substring without repeated characters
猜你喜欢
JS slow motion animation principle teaching (super detail)
2022-7-6 Leetcode 977.有序数组的平方
TPG x AIDU | AI leading talent recruitment plan in progress!
Mathématiques avancées - - chapitre 8 différenciation des fonctions multivariables 1
Redis只能做缓存?太out了!
118. Yanghui triangle
LeetCode简单题分享(20)
1. Deep copy 2. Call apply bind 3. For of in differences
Vmware 与主机之间传输文件
Detr introduction
随机推荐
为租客提供帮助
566. Reshaping the matrix
Leecode3. Longest substring without repeated characters
Redis 核心数据结构 & Redis 6 新特性详
MySQL error 28 and solution
《厌女:日本的女性嫌恶》摘录
Introduction to database system - Chapter 1 introduction [conceptual model, hierarchical model and three-level mode (external mode, mode, internal mode)]
Getting started with MySQL
Error lnk2019: unresolved external symbol
mysql 局域网内访问不到的问题
Attribute keywords aliases, calculated, cardinality, ClientName
Final review notes of single chip microcomputer principle
2022-7-6 sigurg is used to receive external data. I don't know why it can't be printed out
手里的闲钱是炒股票还是买理财产品好?
Learning breakout 2 - about effective learning methods
华为镜像地址
Problems that cannot be accessed in MySQL LAN
LeetCode_二分搜索_中等_153.寻找旋转排序数组中的最小值
1. Deep copy 2. Call apply bind 3. For of in differences
Lavarel之环境配置 .env