• js时间Date格式转换


    获取现在时间 并转换格式

    class Point{
    	nowTime(format){  //时间转换格式
    		let date = new Date(),times;
    		if(format=='yy-mm-dd hh:mm:ss'){//yy-mm-dd hh:mm:ss
    			times=date.getFullYear() +"-"+ 
    			((date.getMonth()+1)>=10?(date.getMonth()+1):'0'+
    			(date.getMonth()+1))  +"-"+ (date.getDate()>=10? date.getDate():'0'+ date.getDate())+" "+
    			(date.getHours()>=10? date.getHours():'0'+ date.getHours())+":"+
    			(date.getMinutes()>=10? date.getMinutes():'0'+ date.getMinutes())+":"+
    			(date.getSeconds()>=10? date.getSeconds():'0'+ date.getSeconds());			
    		}else if(format=='yy-mm-dd'){//yy-mm-dd
    			times = date.toLocaleDateString().replace(///g,'-');
    		}else if(format=='hh:mm:ss'){
    			times = 
    			(date.getHours()>=10? date.getHours():'0'+ date.getHours())+":"+
    			(date.getMinutes()>=10? date.getMinutes():'0'+ date.getMinutes())+":"+
    			(date.getSeconds()>=10? date.getSeconds():'0'+ date.getSeconds());
    		}else{
    			times = date.toLocaleString().replace(///g, "-");
    		}
    		return times;
    	}
    };
    
    let time = new Point();
    console.log(time.nowTime('yy-mm-dd hh:mm:ss'))
    
  • 相关阅读:
    virtualenv -- python虚拟沙盒
    python 多继承详解
    GCDAsyncSocket类库,IOS下TCP通讯使用心得
    TCP长连接与短连接的区别
    SOCKET类型定义及应用
    Ubuntu增加Swap分区大小
    log4j使用说明
    maven资料
    资料推荐
    Idea操作与问题解决
  • 原文地址:https://www.cnblogs.com/1748sb/p/14041579.html
Copyright © 2020-2023  润新知