当前位置:网站首页>【时间格式工具函数的封装】
【时间格式工具函数的封装】
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) { // 大于一分钟小于一小时展示为
边栏推荐
- 单调性约束与反单调性约束的区别 monotonicity and anti-monotonicity constraint
- [STM32] actual combat 3.1 - drive 42 stepper motors with STM32 and tb6600 drivers (I)
- [machine learning 03] Lagrange multiplier method
- PR Lecture Notes
- Graduation season | keep company with youth and look forward to the future together!
- Template initial level template
- MPX plug-in
- 【OneNote】无法连接到网络,无法同步问题
- The fifth training assignment
- Operation method of Orange Pie orangepi 4 lts development board connecting SATA hard disk through mini PCIe
猜你喜欢
uniCloud
Différences entre les contraintes monotones et anti - monotones
[untitled]
[untitled]
Operation method of Orange Pie orangepi 4 lts development board connecting SATA hard disk through mini PCIe
How to use cherry pick?
Opencv installation and environment configuration - vs2017
seata 1.3.0 四種模式解决分布式事務(AT、TCC、SAGA、XA)
Transaction rolled back because it has been marked as rollback-only解决
Avoid mutating a prop directly since the value will be overwritten whenever the parent component
随机推荐
shardingsphere分库分表示例(逻辑表,真实表,绑定表,广播表,单表)
[C #] the solution of WinForm operation zoom (blur)
【亲测可行】error while loading shared libraries的解决方案
VIM命令模式与输入模式切换
【OneNote】无法连接到网络,无法同步问题
seata 1.3.0 四種模式解决分布式事務(AT、TCC、SAGA、XA)
请问申购新股哪个证券公司开户是最好最安全的
[untitled]
Unity websocket server
[pyqt] the cellwidget in tablewidget uses signal and slot mechanism
Go Slice 比较
JSON format query of MySQL
Typescript interface inheritance
How to use cherry pick?
The sixth training assignment
Laya common script commands
PR Lecture Notes
Kitex 重试机制
Typescript interface inheritance
Array object sorting