返回json格式时间,解析时间

传入:Json格式的时间

JS如下:

yyyy-M(MM)-d(dd) H(HH):m(mm):s(ss)

function timeStamp2String(time)
{
  var data=time;
  var datetime=new Date(parseInt(data.replace("/Date(","").replace(")/",""),10));  
  var year=datetime.getFullYear();
  var month=datetime.getMonth()+1;
  var date=datetime.getDate();
  var hour=datetime.getHours();
  var minute=datetime.getMinutes();
  var second=datetime.getSeconds();
  return year+"-"+month+"-"+date+" "+hour+":"+minute+":"+second;
}

  yyyy-MM-dd HH:mm:ss

function timeStamp2String(time)
{
     var data = time;
        var datetime = new Date(parseInt(data.replace("/Date(", "").replace(")/", ""), 10));
        var year = datetime.getFullYear();
        var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
        var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
        var hour = datetime.getHours() < 10 ? "0" + datetime.getHours() : datetime.getHours();
        var minute = datetime.getMinutes() < 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
        var second = datetime.getSeconds() < 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
        return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second; }

运用时,在js中调用

posted @ 2015-11-27 19:41  如此低调的男人  阅读(1461)  评论(0编辑  收藏  举报