我刚搞web开发,用到很多javascript.对它很不了解,有个问题麻烦大家给解决下,如何根据long型的数据得到相应的yyyy-mm-dd hh:mi:ss格式的日期串呢?谢谢大家

解决方案 »

  1.   

    直接 var thedate = new Date(long 型数值);
      

  2.   

    那如何以yyyy-mm-dd hh:mi:ss格式输出到页面 谢谢 :)
      

  3.   

    根据1楼所说的,获取时间后,用toLoaleString()、toLocaleDateString()、toLocaleTimeString()来格式化时间。
    var thedate = new Date()
    var a= thedate.toLoaleString()//输出日期和时间
    var b= thedate.toLocaleDateString()//输出日期
    var c= thedate.toLocaleTimeString()//输出时间
      

  4.   

    使用meizz大哥的日期format方法就好 Date.prototype.Format = function(informat) //author: meizz
    {
    var inputStr = "";
    var format = this.format;
    if(informat!=null)format = informat;
    var o = {
    "M+" : this.getMonth()+1,
    "d+" : this.getDate(),  
    "h+" : this.getHours(),
    "H+" : this.getHours(),
    "m+" : this.getMinutes(),
    "s+" : this.getSeconds()
    }
    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 thedate = new Date(long 型数值);
    alert(thedate.Format("yyyy-MM-dd hh:mm:ss"));