<script type="text/javascript">
 //取当前时间,格式为,yyyy-mm-dd hh:mm:ss
function GetDateT()
 {
  var d,s;
  d = new Date();
  s = d.getYear() + "-";             //取年份
  s = s + (d.getMonth() + 1) + "-";//取月份
  s += d.getDate() + " ";         //取日期
  s += d.getHours() + ":";       //取小时
  s += d.getMinutes() + ":";    //取分
  s += d.getSeconds();         //取秒
  
  return(s);  
 
 } 
myDate=GetDateT()
alert (myDate) 
</script>这是一个方案,还有其它方案吗?急求

解决方案 »

  1.   


    <div id="jnkc">
    </div>
    <script>setInterval("jnkc.innerHTML=new Date().toLocaleString();",1000);
    </script>
      

  2.   

    <script>
    var today =new Date()
    alert((today.toLocaleString().replace(/年|月/g,'-')).replace(/日/g,''))
    </script>
      

  3.   


    function FormatDate(str)
    {
    if (typeof str == "string")
    {
    var arrDateInfo = str.split(" ");
    if (arrDateInfo.length == 2)
    {
    var arrDate = arrDateInfo[0].split("-");
    if (arrDate.length == 3)
    {
    if (arrDate[1].length == 1) arrDate[1] = "0" + arrDate[1];
    if (arrDate[2].length == 1) arrDate[2] = "0" + arrDate[2];

    var arrTime = arrDateInfo[1].split(":");
    if (arrTime.length == 3)
    {
    if (arrTime[0].length == 1) arrTime[0] = "0" + arrTime[0];
    if (arrTime[1].length == 1) arrTime[1] = "0" + arrTime[1];
    if (arrTime[2].length == 1) arrTime[2] = "0" + arrTime[2];

    var szNewDateTime = arrDate[0] + "-" + arrDate[1] + "-" + arrDate[2] + " ";
    szNewDateTime += arrTime[0] + ":" + arrTime[1] + ":" + arrTime[2];

    return szNewDateTime;
    }

    return arrDate[0] + "-" + arrDate[1] + "-" + arrDate[2] + " " + arrDateInfo[1];
    }
    }
    }

    return str;
    }
    因为之前没用过 toLocaleString,所以自己写了个函数~~不过 toLocaleString 按字面理解,应该是把日期转换成客户端电脑的时间格式~~万一(只是万一,几率可能很小),某人的电脑格式是 yyyy-m-d h:n:s 的话怎么办呢.....
      

  4.   

    <script type="text/javascript">
     //取当前时间,格式为,yyyy-mm-dd hh:mm:ss
    function GetCurrentDate(){     return new Date().format("yyyy-MM-dd"); 

    </script>