当前位置:网站首页>【时间格式工具函数的封装】
【时间格式工具函数的封装】
2022-07-07 09:08:00 【果东布丁】
timegs.js
export default function formatMsgTime (timespan) {
var dateTime = new Date(timespan) // 将传进来的字符串或者毫秒转为标准时间
var year = dateTime.getFullYear()
var month = dateTime.getMonth() + 1
var day = dateTime.getDate()
var hour = dateTime.getHours()
var minute = dateTime.getMinutes()
// var second = dateTime.getSeconds()
var millisecond = dateTime.getTime() // 将当前编辑的时间转换为毫秒
var now = new Date() // 获取本机当前的时间
var nowNew = now.getTime() // 将本机的时间转换为毫秒
var milliseconds = 0
var timeSpanStr
milliseconds = nowNew - millisecond
if (milliseconds <= 1000 * 60 * 1) { // 小于一分钟展示为刚刚
timeSpanStr = '刚刚'
} else if (1000 * 60 * 1 < milliseconds && milliseconds <= 1000 * 60 * 60) { // 大于一分钟小于一小时展示为
边栏推荐
- Interprocess communication (IPC)
- After the uniapp jumps to the page in onlaunch, click the event failure solution
- Arduino board description
- 2021-04-23
- 通过 Play Integrity API 的 nonce 字段提高应用安全性
- Idea shortcut keys
- Go slice comparison
- Activity生命周期
- Une fois que l'uniapp a sauté de la page dans onlaunch, cliquez sur Event Failure resolution
- Unity websocket server
猜你喜欢
Unity script generates configurable files and loads
SQL Server knowledge gathering 9: modifying data
【安装系统】U盘安装系统教程,使用UltraISO制作U盘启动盘
Unity script visualization about layout code
[untitled]
oracle常见锁表处理方式
VR development optimization
Antd select selector drop-down box follows the scroll bar to scroll through the solution
Operation method of Orange Pie orangepi 4 lts development board connecting SATA hard disk through mini PCIe
[STM32] actual combat 3.1 - drive 42 stepper motors with STM32 and tb6600 drivers (I)
随机推荐
Idea shortcut keys
Wallhaven wallpaper desktop version
关于jmeter中编写shell脚本json的应用
SQL Server knowledge collection 11: Constraints
软件设计之——“高内聚低耦合”
Some online academic report websites and machine learning videos
Arduino receives and sends strings
"Dream Cup" 2017 Jiangsu information and future primary school summer camp it expert PK program design questions
毕业季|与青春作伴,一起向未来!
單調性約束與反單調性約束的區別 monotonicity and anti-monotonicity constraint
When initializing 'float', what is the difference between converting to 'float' and adding 'f' as a suffix?
滚动踩坑--UNI_APP(八)
Unity determines whether the mouse clicks on the UI
高考作文,高频提及科技那些事儿……
数据库同步工具 DBSync 新增对MongoDB、ES的支持
uniCloud
Opencv installation and environment configuration - vs2017
JS add spaces to the string
[untitled]
常用sql语句整理:mysql