js日期函数

function getTimeFormatByType(time,type){
if(!time)return;
var date;
if(typeof(time)=='string'){
if(time.indexOf("T")>0){
   date=new Date(time.substring(0,10) + 'T' + time.substring(11));
}else{
date=justep.Date.fromString(time, 'yyyy-MM-dd hh:mm:ss');
}
}else{ 
date=new Date(time); 


   var year=date.getFullYear();   //获取系统的年;
                    var mouth=date.getMonth()+1;
    var today=date.getDate();
    var hours=date.getHours();
            var minutes= date.getMinutes();
            var Seconds=date.getSeconds(); //秒
    if(mouth<=9) mouth = "0"+mouth; 
    if(hours<=9) hours = "0"+hours;
   if(today <= 9) today = "0"+today;      
                    if(minutes <= 9) minutes = "0"+minutes;
                    if(Seconds <= 9) Seconds = "0"+Seconds;
                    if(type==1){//2017-08-07 10:53:55
                     return year+"-"+mouth+"-"+today+" "+hours+":"+minutes+":"+Seconds;  
                    }
                    if(type==2){//08-07 10:53
                 return mouth+"-"+today+" "+hours+":"+minutes;
                    }
                    if(type==3){//2017-08-07
                    return year+"-"+mouth+"-"+today;
                    }
                    if(type==4){// 10:53
                     return hours+":"+minutes;
                    }
                    if(type==5){// 08-07
                     return mouth+"-"+today;
                    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值