var arr = new Array();
var strI = "2006-7-1";
arr = strI.split("-");
alert(arr[0]+"-0"+arr[1]+"-0"+arr[2]);

解决方案 »

  1.   


    rq="输入的日期"
    var rqArray = rq.split("-");
    var zhrq =rqArray[0]; 
    for(var i=1;i<3;i++){
         if(rqArray[i]<=9){
               rqArray[i]="0"+rqArray[i];
         }
         zhrq = zhrq+"-"+rqArray[i];
    }
    alert(zhrq);
      

  2.   

    谢谢
    fuyanling() 
    现在结贴
      

  3.   

    http://community.csdn.net/Expert/TopicView.asp?id=4874778
      

  4.   

    <script language="javascript">//<!--
    var s="2006-7-1";
    var r=/(\-)(\d{1}?)/gim;
    alert(s.replace(r,"$10$2"));
    //--></script>
      

  5.   

    var s = "2006-7-1";
    s = s.replace(/\d+/g, function(v) {return v.length%2 ? '0'+v : v;});alert(s);
      

  6.   

    <SCRIPT LANGUAGE="JavaScript">
    <!--
    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 s = "2006-7-1";
    var d = new Date(s.replace(/-/g, "/"));
    alert(d.format("yyyy-MM-dd"));
    alert(d.format("MM-dd-yyyy"));
    alert(d.format("yyyy年MM月dd日"));
    //-->
    </SCRIPT>