当前位置:网站首页>【时间格式工具函数的封装】
【时间格式工具函数的封装】
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) { // 大于一分钟小于一小时展示为边栏推荐
猜你喜欢
随机推荐
Go slice comparison
Idea shortcut keys
After the uniapp jumps to the page in onlaunch, click the event failure solution
Bookmarking - common website navigation for programmers
[untitled]
毕业季|与青春作伴,一起向未来!
2021-04-08
[untitled]
香橙派OrangePi 4 LTS开发板通过Mini PCIE连接SATA硬盘的操作方法
Shardingsphere sub database and table examples (logical table, real table, binding table, broadcast table, single table)
How to remove addition and subtraction from inputnumber input box
Ping tool ICMP message learning
Operation method of Orange Pie orangepi 4 lts development board connecting SATA hard disk through mini PCIe
Vscode 尝试在目标目录创建文件时发生一个错误:拒绝访问【已解决】
Eth trunk link switching delay is too high
JS implementation chain call
基于Retrofit框架的金山API翻译功能案例
Records on the use of easyflash v3.3
seata 1.3.0 四种模式解决分布式事务(AT、TCC、SAGA、XA)
Unity websocket client







![[untitled]](/img/8e/e968d4629004bb0c3ee70328b6777b.jpg)

