当前位置:网站首页>The time difference between the past time and the present time of uniapp processing, such as just, a few minutes ago, a few hours ago, a few months ago
The time difference between the past time and the present time of uniapp processing, such as just, a few minutes ago, a few hours ago, a few months ago
2022-07-04 10:06:00 【gblfy】
List of articles
1. Message returned
Format time :createTime
[{
"id": "62c11d3435b7c4007a8e650e",
"fromUserId": "21100598TZ9XG6RP",
"fromNickname": " Little beauty ",
"fromFace": "http://gblfy.cn:9000/imooc/xh.jpg",
"toUserId": "220620BZ2DH0KP94",
"msgType": 1,
"msgContent": {
"isFriend": true
},
"createTime": "2022-07-03 12:38:11"
}
... Other data omitted
]
2. Time format method
App.vue Define global methods , Easy to call , It can also be extracted separately and put into the tool class
methods: {
// The time format time is : just 、 How many minutes ago 、 How many days ago
// stringTime 2020-09-10 20:20:20
getDateBeforeNow(stringTime) {
console.log(" The parameter is not formatted ", stringTime);
stringTime = new Date(stringTime.replace(/-/g, '/'))
// Unified unit conversion
var minute = 1000 * 60;
var hour = minute * 60;
var day = hour * 24;
var week = day * 7;
var month = day * 30;
var year = month * 12;
var time1 = new Date().getTime(); // The current timestamp
console.log(" current time ", time1);
// Millisecond unit conversion of time
var time2 = new Date(stringTime).getTime(); // Timestamp of the specified time
console.log(" The time of transmission ", time2);
var time = time1 - time2;
console.log(" Time after calculation ", time);
var result = null;
if (time < 0) {
// alert(" The set time cannot be earlier than the current time !");
result = stringTime;
} else if (time / year >= 1) {
result = parseInt(time / year) + " Years ago ";
} else if (time / month >= 1) {
result = parseInt(time / month) + " Month ago, ";
} else if (time / week >= 1) {
result = parseInt(time / week) + " Zhou Qian ";
} else if (time / day >= 1) {
result = parseInt(time / day) + " Days ago, ";
} else if (time / hour >= 1) {
result = parseInt(time / hour) + " Hours before ";
} else if (time / minute >= 1) {
result = parseInt(time / minute) + " Minutes ago ";
} else {
result = " just ";
}
console.log(" Formatted time ", result);
return result;
},
}
3. Use
page
<template>
<view class="msg-item-middle">
<text class="user-nickname">{
{
msg.fromNickname}}</text>
<text class="msg-content"> Pay attention to you {
{
getGraceDateBeforeNow(msg.createTime)}}</text>
</view>
</template>
Method area
<script>
var app = getApp();
export default {
methods: {
// Time display optimization just 、 A few minutes ago , A few hours ago , A few months ago
getGraceDateBeforeNow(dateTimeStr) {
return getApp().getDateBeforeNow(dateTimeStr);
},
}
}
</script>
边栏推荐
- Go context basic introduction
- El Table Radio select and hide the select all box
- 浅谈Multus CNI
- Nuxt reports an error: render function or template not defined in component: anonymous
- 使用 C# 提取 PDF 文件中的所有文字(支持 .NET Core)
- IIS configure FTP website
- xxl-job惊艳的设计,怎能叫人不爱
- libmysqlclient. so. 20: cannot open shared object file: No such file or directory
- Legion is a network penetration tool
- 品牌连锁店5G/4G无线组网方案
猜你喜欢
El Table Radio select and hide the select all box
Devop basic command
SSM online examination system source code, database using mysql, online examination system, fully functional, randomly generated question bank, supporting a variety of question types, students, teache
Hands on deep learning (34) -- sequence model
H5 audio tag custom style modification and adding playback control events
QTreeView+自定义Model实现示例
对于程序员来说,伤害力度最大的话。。。
自动化的优点有哪些?
Application of safety monitoring in zhizhilu Denggan reservoir area
技术管理进阶——如何设计并跟进不同层级同学的绩效
随机推荐
MySQL transaction mvcc principle
原生div具有编辑能力
lolcat
[200 opencv routines] 218 Multi line italic text watermark
Write a jison parser from scratch (2/10): learn the correct posture of the parser generator parser generator
Get the source code in the mask with the help of shims
直方图均衡化
Whether a person is reliable or not, closed loop is very important
libmysqlclient.so.20: cannot open shared object file: No such file or directory
El Table Radio select and hide the select all box
View CSDN personal resource download details
How to display √ 2 on the command line terminal ̅? This is actually a blog's Unicode test article
Intelligent gateway helps improve industrial data acquisition and utilization
MongoDB数据日期显示相差8小时 原因和解决方案
Kotlin: collection use
AUTOSAR从入门到精通100讲(106)-域控制器中的SOA
Laravel文档阅读笔记-How to use @auth and @guest directives in Laravel
Legion is a network penetration tool
Mmclassification annotation file generation
Batch distribution of SSH keys and batch execution of ansible