Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
web-framework-temp
/
vue-cli3-vt-template-master
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
92e1116e
authored
2022-06-24 18:47:45 +0800
by
simon
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
默认提交
1 parent
1d5736bf
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
0 deletions
src/utils/utils.js
src/utils/utils.js
View file @
92e1116
...
...
@@ -169,6 +169,35 @@ export function formatBr(str) {
return
str
};
/**
* 格式化日期时间 支持Date和时间戳
* @param {date} date 日期时间
* @param {string} fmt 格式,如:'yyyy-MM-dd hh:mm:ss'
*/
export
function
formatDate
(
date
,
fmt
)
{
if
(
!
date
)
return
'-'
// 把-换成/ 避免iOS和安卓真机问题
var
reg
=
/-/g
;
date
=
date
&&
date
.
replace
(
reg
,
'/'
);
date
=
new
Date
(
date
)
const
o
=
{
'M+'
:
date
.
getMonth
()
+
1
,
// 月份
'd+'
:
date
.
getDate
(),
// 日
'h+'
:
date
.
getHours
(),
// 小时
'm+'
:
date
.
getMinutes
(),
// 分
's+'
:
date
.
getSeconds
(),
// 秒
'q+'
:
Math
.
floor
((
date
.
getMonth
()
+
3
)
/
3
),
// 季度
S
:
date
.
getMilliseconds
()
// 毫秒
}
if
(
/
(
y+
)
/
.
test
(
fmt
))
fmt
=
fmt
.
replace
(
RegExp
.
$1
,
(
date
.
getFullYear
()
+
''
).
substr
(
4
-
RegExp
.
$1
.
length
))
for
(
const
k
in
o
)
{
if
(
new
RegExp
(
'('
+
k
+
')'
).
test
(
fmt
))
fmt
=
fmt
.
replace
(
RegExp
.
$1
,
(
RegExp
.
$1
.
length
==
1
)
?
(
o
[
k
])
:
((
'00'
+
o
[
k
]).
substr
((
''
+
o
[
k
]).
length
)))
}
return
fmt
}
/**
* @desc 函数防抖
...
...
Please
register
or
sign in
to post a comment