Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
taobao-mini-template
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
2
Issues
2
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
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
qinhaitao
taobao-mini-template
Commits
5a987d7c
Commit
5a987d7c
authored
Jan 20, 2021
by
qinhaitao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:
🎸
时间格式化
parent
5ed33856
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
0 deletions
+33
-0
date.ts
v2.0/src/utils/common/date.ts
+33
-0
No files found.
v2.0/src/utils/common/date.ts
0 → 100644
View file @
5a987d7c
/** @format */
import
*
as
dayjs
from
'dayjs'
import
{
getEndTimestamp
,
getStartTimestamp
,
transformBeijingDate
}
from
'../../sdk'
const
EIGHT_HOURS
=
8
*
60
*
60
*
1000
/**
* 格式化时间 统一处理8小时时差问题
* YYYY-MM-DDTHH:mm:ss
*
* formatDate().format('YYYY-MM-DD HH:mm:ss')
* formatDate('2021/01/21').getStartTimestamp()
* formatDate('2021/01/21').getEndTimestamp()
* formatDate('2021/01/21').getTimestamp()
* @export
* @param {(string | number)} date
* @return {
* format 格式化时间
* getTimestamp 时间戳
* getStartTimestamp 某天开始的时间戳
* getEndTimestamp 某天结束的时间戳
* }
*/
export
function
formatDate
(
date
:
string
|
number
=
Date
.
now
())
{
const
beijingDate
=
typeof
date
===
'string'
?
new
Date
(
date
)
:
transformBeijingDate
(
date
)
return
{
format
:
(
template
=
'YYYY-MM-DD'
)
=>
dayjs
(
beijingDate
).
format
(
template
),
getTimestamp
:
()
=>
(
typeof
date
===
'number'
?
date
:
dayjs
(
date
).
valueOf
()
-
EIGHT_HOURS
),
getStartTimestamp
:
()
=>
getStartTimestamp
(
dayjs
(
beijingDate
).
format
(
'YYYY/MM/DD'
)),
getEndTimestamp
:
()
=>
getEndTimestamp
(
dayjs
(
beijingDate
).
format
(
'YYYY/MM/DD'
))
}
}
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