Created
November 28, 2019 10:45
-
-
Save Bachana123/82e5fcefd8dfd7ad8971a3d0289a56fe to your computer and use it in GitHub Desktop.
format for date vue.nuxt
This file contains 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
format(time, format) { | |
var t = new Date(time); | |
var tf = function (i) { return (i < 10 ? '0' : '') + i }; | |
return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function (a) { | |
switch (a) { | |
case 'yyyy': | |
return tf(t.getFullYear()); | |
break; | |
case 'MM': | |
return tf(t.getMonth() + 1); | |
break; | |
case 'mm': | |
return tf(t.getMinutes()); | |
break; | |
case 'dd': | |
return tf(t.getDate()); | |
break; | |
case 'HH': | |
return tf(t.getHours()); | |
break; | |
case 'ss': | |
return tf(t.getSeconds()); | |
break; | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment