Created
February 14, 2018 01:51
-
-
Save starfeeling/a626dfd73c826437a9cda60747e9ee5a to your computer and use it in GitHub Desktop.
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
function format(val, figure) { | |
return val < 10 * (figure - 1) ? `0${val}` : `${val}`; | |
} | |
function dateformat(dateObject) { | |
const date = dateObject || new Date(); | |
const year = format(date.getFullYear(), 4); | |
const month = format(date.getMonth() + 1, 2); | |
const day = format(date.getDate(), 2); | |
const hour = format(date.getHours(), 2); | |
const minute = format(date.getMinutes(), 2); | |
const second = format(date.getSeconds(), 2); | |
return { | |
year, | |
month, | |
day, | |
hour, | |
minute, | |
second | |
}; | |
} | |
module.exports = dateformat; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment