Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gic-cli
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gic-web
gic-cli
Commits
0ebacfe8
Commit
0ebacfe8
authored
Oct 31, 2022
by
caoyanzhi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update: 日期格式化方法
parent
c007357a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
0 deletions
+27
-0
App.vue
src/App.vue
+2
-0
formatters.js
utils/formatters.js
+25
-0
No files found.
src/App.vue
View file @
0ebacfe8
...
...
@@ -8,8 +8,10 @@
<
script
>
import
{
projectName
}
from
'@/config/index.js'
;
import
formatters
from
'../utils/formatters.js'
;
export
default
{
name
:
'App'
,
provide
:
{
formatters
},
data
()
{
return
{
projectName
,
...
...
utils/formatters.js
0 → 100644
View file @
0ebacfe8
// 在vue文件中使用inject: ['formatters'],即可通过formatters的属性访问格式化方法
export
default
{
/**
* @desc 格式化日期
* @param {*} date Date对象或者时间戳
* @param {*} type 日期格式,支持yyyy-MM-dd HH:mm:ss的任意组合,默认返回yyyy-MM-dd HH:mm:ss
* @returns
*/
formatDate
(
date
,
type
=
'yyyy-MM-dd HH:mm:ss'
)
{
if
(
!
date
)
return
'--'
;
const
d
=
new
Date
(
date
);
const
result
=
{
yyyy
:
d
.
getFullYear
(),
MM
:
(
d
.
getMonth
()
+
1
).
toString
().
padStart
(
2
,
'0'
),
dd
:
d
.
getDate
().
toString
().
padStart
(
2
,
'0'
),
HH
:
d
.
getHours
().
toString
().
padStart
(
2
,
'0'
),
mm
:
d
.
getMinutes
().
toString
().
padStart
(
2
,
'0'
),
ss
:
d
.
getSeconds
().
toString
().
padStart
(
2
,
'0'
),
};
Object
.
keys
(
result
).
forEach
((
k
)
=>
{
type
=
type
.
replace
(
k
,
result
[
k
]);
});
return
type
;
},
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment