当前位置:网站首页>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>
边栏推荐
- Realize the IP address home display function and number home query
- 3D Detection: 3D Box和点云 快速可视化
- 648. 单词替换 : 字典树的经典运用
- move base参数解析及经验总结
- 云计算安全扩展要求关注的安全目标和实现方式区分原则有哪些?
- Introduction to database system - Chapter 1 introduction [conceptual model, hierarchical model and three-level mode (external mode, mode, internal mode)]
- LeetCode_二分搜索_中等_153.寻找旋转排序数组中的最小值
- [1] ROS2基础知识-操作命令总结版
- Error lnk2019: unresolved external symbol
- 2022-7-6 初学redis(一)在 Linux 下下载安装并运行 redis
猜你喜欢
Realize the IP address home display function and number home query
Thread pool reject policy best practices
LeetCode简单题分享(20)
2022-7-6 Leetcode27.移除元素——太久没有做题了,为双指针如此狼狈的一天
Navicat run SQL file import data incomplete or import failed
2022-7-6 Leetcode 977. Square of ordered array
[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
Indoor ROS robot navigation commissioning record (experience in selecting expansion radius)
室內ROS機器人導航調試記錄(膨脹半徑的選取經驗)
1、深拷贝 2、call apply bind 3、for of for in 区别
随机推荐
数据库系统概论-第一章绪论【概念模型、层次模型和三级模式(外模式、模式、内模式)】
Huawei image address
SSRF漏洞file伪协议之[网鼎杯 2018]Fakebook1
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
Battle Atlas: 12 scenarios detailing the requirements for container safety construction
Custom thread pool rejection policy
2022-7-6 Leetcode27.移除元素——太久没有做题了,为双指针如此狼狈的一天
AI人才培育新思路,这场直播有你关心的
Laravel form builder uses
Laravel Form-builder使用
供应链供需预估-[时间序列]
call undefined function openssl_ cipher_ iv_ length
PHP中用下划线开头的变量含义
Laravel5 call to undefined function openssl cipher iv length() 报错 PHP7开启OpenSSL扩展失败
接口自动化测试-接口间数据依赖问题解决
Deep understanding of array related problems in C language
Ogre introduction
Vmware共享主机的有线网络IP地址
10 pictures open the door of CPU cache consistency
Flink | 多流转换