獲取時間格式

1.獲取年月日時間格式

 getTime(time){
        if(time==null||time<0){
            return ""
        }
        var date=new Date(time);
        var day=('0'+date.getDate()).slice(-2);
        var month=('0'+date.getMonth()+1).slice(-2);
        var today=date.getFullYear()+"-"+month+"-"+day;
        return today
    },

2.獲取包含時分秒的時間格式

getAllTime(time){
        if(time==null||time<0){
            return ""
        }
        var date=new Date(time);
        var day=('0'+date.getDate()).slice(-2);
        var month=('0'+date.getMonth()).slice(-2);
        var h=('0'+date.getHours()).slice(-2);
        var m=('0'+date.getMinutes()).slice(-2);
        var s=('0'+date.getSeconds()).slice(-2);
        var today=date.getFullYear+"-"+month+"-"+day+''+h+":"+m+":"+s;
        return today;
    },

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章