Created
April 8, 2020 02:05
-
-
Save kevinjie/e99db7bc7272d4cc3761411ce8333725 to your computer and use it in GitHub Desktop.
[TIME_HANDLER] 时间处理方法 #TIME
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const formatNumber = n => { | |
n = n.toString() | |
return n[1] ? n : '0' + n | |
} | |
export const formatTime = date => { | |
const year = date.getFullYear() | |
const month = date.getMonth() + 1 | |
const day = date.getDate() | |
const hour = date.getHours() | |
const minute = date.getMinutes() | |
const second = date.getSeconds() | |
return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment