zoukankan      html  css  js  c++  java
  • 时间戳与各种时间格式之间的转换

    var common={

      /*时间戳与的转换
      */
      //获得当前时间戳的三种方式
      _timestemp:function(){
        return Date.parse(new Date())/1000;//=>1498983745

        //二:new Date().valueOf();/=>1498983687749

        //三:new Date().getTime();//=>1498983687749
      },
      //时间戳转换成时间: 2011-3-16 16:50:43 (这种格式有一个缺点就是格式不统一,可能出现2011/3/16 下午16:50:43这种格式,这是由LocalString引起的)
      _getDateHasHorizontalLine:function(timestemp){
        return new Date(parseInt(timestemp) * 1000).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");
      },
      //时间戳转换成时间: 2011/3/16 16:50:43 (缺点同上)
      _getDateHasSlash:function(timestemp){
        return new Date(parseInt(timestemp) * 1000).toLocaleString().replace("-","/").replace("-","/");
      },
      //时间戳转换成时间: 2011年3月16日 16:50:43(这个常用,以免在不同的设备上格式不统一)
      _getDateHasHoursMinutesSecondes:function(timestemp){
        var time=new Date(parseInt(timestemp) * 1000),
          timeFormat,
          minutes,
          seconds;
         minutes=time.getMinutes();
         seconds=time.getSeconds();
        if(minutes<10){
          minutes="0"+time.getMinutes();
        }
        if(seconds<10){
          seconds="0"+time.getSeconds();
        }
        timeFormat=time.getFullYear()+"年"
            +(time.getMonth()+1)+"月"
            +time.getDate()+"日"+" "
            +time.getHours()+":"
            +minutes+":"
            +seconds;
        return   timeFormat;
      },
      //时间戳转换成时间: 2011-3-16
      _getDateNoMilliSecond:function(timestemp){
        return new Date(parseInt(timestemp) * 1000).toLocaleDateString();
      }

    }

    焦大叔叔
  • 相关阅读:
    mac与ip为什么同时存在
    tcp四次挥手
    tcp三次握手
    GET与POST的区别
    Servlet.service() for servlet [jsp] in context ....错误
    c3p0连接数据库时注意事项
    finalize()及垃圾回收
    composer 安装新包失败的原因之一
    如何使用优酷开放平台获取视频播放列表
    php解析优酷网上的视频资源去广告
  • 原文地址:https://www.cnblogs.com/tiny-jiao/p/7106398.html
Copyright © 2011-2022 走看看