Js时间格式化
主页
Java
服务器
Docker
报错
前端
标签
文章
```javascript window.formatDate = function (date, format) { if (date.getTime() === 0) { return '' } let o = { 'M+': date.getMonth() + 1, // month 'd+': date.getDate(), // day 'h+': date.getHours(), // hour 'H+': date.getHours(), // hour 'm+': date.getMinutes(), // minute 's+': date.getSeconds(), // second 'q+': Math.floor((date.getMonth() + 3) / 3), // quarter 'S': date.getMilliseconds() // millisecond } if (/(y+)/.test(format)) { format = format.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length)) } for (let k in o) { if (new RegExp('(' + k + ')').test(format)) { format = format.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length)) } } return format } ``` - 如果是timestamp,可以加一句转换Date ```javascript const date = new Date(timestamp); ``` **参考文档** https://www.zhihu.com/question/590782329?utm_id=0
上一篇:
Vue.js + element-ui + tinymce 实现富文本(不使用脚手架)
下一篇:
Enum枚举类通过key获取value
COMMENT
Sign in
to leave a comment.
No Leanote account ?
Sign up now
.
0
comments
More...
Title
-
Artist
0:00
No Leanote account ? Sign up now.