zoukankan      html  css  js  c++  java
  • JS DATE对象详解

    1、建立时间对象:可获取年,月,日,星期,时,分,秒

    var d = new Date();
    console.log(d.getFullYear()+'年'+d.getMonth()+'月'+d.getDate()+'星期'+d.getDay()+'日'+d.getHours()+'小时'+d.getMinutes()+'分'+d.getSeconds()+'秒');
    

     2、获取时间戳

    console.log(d.getTime());
    

     3、时间转换公式

    	Math.floor(t/86400) //天
    	Math.floor(t%86400/3600) //时
    	Math.floor(t%86400%3600/60) //分
    	t%60 //秒
    

     4、js格式化日期

    var format = function(time, format){
        var t = new Date(time);
        var tf = function(i){return (i < 10 ? '0' : '') + i};
        return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function(a){
        switch(a){
            case 'yyyy':
            return tf(t.getFullYear());
            break;
            case 'MM':
            return tf(t.getMonth() + 1);
            break;
            case 'mm':
            return tf(t.getMinutes());
            break;
            case 'dd':
            return tf(t.getDate());
            break;
            case 'HH':
            return tf(t.getHours());
            break;
            case 'ss':
            return tf(t.getSeconds());
            break;
        }
        })
    }
    format(new Date().getTime(), 'yyyy-MM-dd HH:mm:ss')//getTime返回距 1970 年 1 月 1 日之间的毫秒数
    
  • 相关阅读:
    解决粘包问题
    粘包问题
    模拟ssh功能
    套接字接上链接循环
    套接字加入通讯循环
    简单通信
    网络编程
    单例模式
    记录一下:chrome上,把网页保存为文件的插件
    centos6.5 64bit 实现root开机自动登录X桌面
  • 原文地址:https://www.cnblogs.com/ilovexiaoming/p/4630583.html
Copyright © 2011-2022 走看看