Skip to content

Instantly share code, notes, and snippets.

@kevinjie
Created April 8, 2020 02:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinjie/e99db7bc7272d4cc3761411ce8333725 to your computer and use it in GitHub Desktop.
Save kevinjie/e99db7bc7272d4cc3761411ce8333725 to your computer and use it in GitHub Desktop.
[TIME_HANDLER] 时间处理方法 #TIME
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