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();
      }

    }

    焦大叔叔
  • 相关阅读:
    html笔记之表单标签
    删除重复字符
    OC点语法和变量作用域
    PHP-You don’t have permissions to access xxx on this server!
    从70周年阅兵式寻找使命
    做市场需要的智能眼镜可以赚钱
    《华为你学不会》读书笔记
    做智能眼镜是为了更方便地拍摄
    智能眼镜是头戴式摄像机
    DA14580_583_DK_II开发板入门笔记
  • 原文地址:https://www.cnblogs.com/tiny-jiao/p/7106398.html
Copyright © 2011-2022 走看看