-
-
Save shuiRong/c1bf301423c96630a2128f9037b92ef3 to your computer and use it in GitHub Desktop.
CST格式时间的格式化 yy-mm-dd
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
var str = 'Tue Jan 09 2018 00:00:00 GMT+0800 (CST)'; | |
var getFormatDate = function (str) { | |
var monthToNumber = { | |
"Jan": "01", | |
"Feb": "02", | |
"Mar": "03", | |
"Apr": "04", | |
"May": "05", | |
"Jun": "06", | |
"Jul": "07", | |
"Aug": "08", | |
"Sep": "09", | |
"Oct": "10", | |
"Nov": "11", | |
"Dec": "12" | |
}; | |
var year = str.match('.{11}(.{4})')[1]; | |
var month = monthToNumber[str.match('.{4}(.{3})')[1]]; | |
var day = str.match('.{8}(.{2})')[1]; | |
return year + '-' + month + '-' + day; | |
} | |
getFormatDate(str) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment