怎么将这种类型
Mon Sep 15 00:00:00 CEST 2008
的日期转化为 
2008-10-15

解决方案 »

  1.   

    function formatDate(D)
    {//调整时间显示格式2007-01-01 12:00:00
    return D.getFullYear() + "-" + (D.getMonth() + 1) + "-" + D.getDate() + " " + D.getHours() + ":" + D.getMinutes() + ":" + D.getSeconds();
    }
    alert("转化前:" + new Date());
    alert("转化后:" + formatDate(new Date()));
      

  2.   


    if(!Date.prototype.format){//日期格式化
        Date.prototype.format = function(format)
        {
            var o =
            {
                "M+" : this.getMonth()+1, //month
                "d+" : this.getDate(),    //day
                "h+" : this.getHours(),   //hour
                "m+" : this.getMinutes(), //minute
                "s+" : this.getSeconds(), //second
                "q+" : Math.floor((this.getMonth()+3)/3),  //quarter
                "S" : this.getMilliseconds() //millisecond
            }
            if(/(y+)/.test(format))
            format=format.replace(RegExp.$1,(this.getFullYear()+"").substr(4 - RegExp.$1.length));
            for(var k in o)
            if(new RegExp("("+ k +")").test(format))
            format = format.replace(RegExp.$1,RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
            return format;
        };
    }
    var str="Mon Sep 15 00:00:00 CEST 2008 ";
    var d=new Date();
    alert(d.format("yyyy-MM-dd"));
      

  3.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <script type="text/javascript">
    window.onload = function(){

    var dd = 'Mon Sep 15 00:00:00 CEST 2008';
    var arr = dd.split(' ');
    ri = '';
    year = '';
    for(var i = 0; i < arr.length; i++){
    if(arr[i].length == 2 && !isNaN(arr[i])){
    ri = arr[i];
    }else if(arr[i].length == 4 && !isNaN(arr[i])){
    year = arr[i];
    }
    }
    alert(year + '-' + ri);
    }
    </script>
    </head><body>
    </body>
    </html>
      

  4.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <script type="text/javascript">
    window.onload = function(){

    var dd = 'Mon Sep 15 00:00:00 CEST 2008';
    var arr = dd.split(' ');
    var ri = '';
    var year = '';
    var month = '';
    for(var i = 0; i < arr.length; i++){
    if(arr[i].length == 2 && !isNaN(arr[i])){
    ri = arr[i];
    }else if(arr[i].length == 4 && !isNaN(arr[i])){
    year = arr[i];
    }
    switch(arr[i]){
    case 'Sep':month = 10;break;
    }
    }
    alert(year + '-' + month + '-' + ri);
    }
    </script>
    </head><body>
    </body>
    </html>
      

  5.   

    才看到我刚才出来的当前日期
    不行将中间的替换掉
    改下:var str="Mon Sep 15 00:00:00 CEST 2008";
    str=str.replace("CEST","");
    var d=new Date(str);
    alert(d.format("yyyy-MM-dd"));lz看我倒数第三个帖子