Skip to content

Instantly share code, notes, and snippets.

@shuiRong
Created January 31, 2018 09:51
Show Gist options
  • Save shuiRong/c1bf301423c96630a2128f9037b92ef3 to your computer and use it in GitHub Desktop.
Save shuiRong/c1bf301423c96630a2128f9037b92ef3 to your computer and use it in GitHub Desktop.
CST格式时间的格式化 yy-mm-dd
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