JS日期格式转换


Fri Oct 31 18:00:00 UTC+0800 2008

转为   

2008-10-31

 

function Todate(num) { //Fri Oct 31 18:00:00 UTC+0800 2008
            num = num + "";
            var date = "";
            var month = new Array();
            month["Jan"] = 1; month["Feb"] = 2; month["Mar"] = 3; month["Apr"] = 4; month["May"] = 5; month["Jun"] = 6;
            month["Jul"] = 7; month["Aug"] = 8; month["Sep"] = 9; month["Oct"] = 10; month["Nov"] = 11; month["Dec"] = 12;
            var week = new Array();
            week["Mon"] = ""; week["Tue"] = ""; week["Wed"] = ""; week["Thu"] = ""; week["Fri"] = ""; week["Sat"] = ""; week["Sun"] = "";
            str = num.split(" ");
            date = str[5] + "-";
            date = date + month[str[1]] + "-" + str[2];
            return date;
}

 

posted @ 2016-12-06 15:46  对我有点小自信  阅读(411)  评论(0编辑  收藏  举报