当前位置:网站首页>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>
边栏推荐
- Golang defer
- Golang type comparison
- Write a jison parser from scratch (4/10): detailed explanation of the syntax format of the jison parser generator
- Go context basic introduction
- 【OpenCV 例程200篇】218. 多行倾斜文字水印
- xxl-job惊艳的设计,怎能叫人不爱
- Hands on deep learning (41) -- Deep recurrent neural network (deep RNN)
- Exercise 9-4 finding books (20 points)
- View CSDN personal resource download details
- Write a jison parser (7/10) from scratch: the iterative development process of the parser generator 'parser generator'
猜你喜欢
PHP student achievement management system, the database uses mysql, including source code and database SQL files, with the login management function of students and teachers
Hands on deep learning (35) -- text preprocessing (NLP)
Devop basic command
H5 audio tag custom style modification and adding playback control events
Application of safety monitoring in zhizhilu Denggan reservoir area
How web pages interact with applets
Hands on deep learning (46) -- attention mechanism
C # use gdi+ to add text with center rotation (arbitrary angle)
pcl::fromROSMsg报警告Failed to find match for field ‘intensity‘.
对于程序员来说,伤害力度最大的话。。。
随机推荐
【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
C language pointer classic interview question - the first bullet
Get the source code in the mask with the help of shims
How can people not love the amazing design of XXL job
How to display √ 2 on the command line terminal ̅? This is actually a blog's Unicode test article
Legion is a network penetration tool
Launpad | 基礎知識
C语言指针经典面试题——第一弹
Nuxt reports an error: render function or template not defined in component: anonymous
Hands on deep learning (45) -- bundle search
C language pointer interview question - the second bullet
Hands on deep learning (III) -- Torch Operation (sorting out documents in detail)
什么是 DevSecOps?2022 年的定义、流程、框架和最佳实践
Hands on deep learning (43) -- machine translation and its data construction
Service developers publish services based on EDAs
基于线性函数近似的安全强化学习 Safe RL with Linear Function Approximation 翻译 1
品牌连锁店5G/4G无线组网方案
【Day1】 deep-learning-basics
Upgrading Xcode 12 caused Carthage to build cartfile containing only rxswift to fail
Servlet基本原理与常见API方法的应用