时间戳转化成年月日时分秒格式

//  js 获取系统当前时间
        var nowdate = new Date();
        var y = nowdate.getFullYear();
        var m = nowdate.getMonth()+1;
        var d = nowdate.getDate();
        var formatnowdate = y+'-'+m+'-'+d;
        $("#enddate").datebox("setValue",formatnowdate);
        //获取系统前一周的时间
        var oneweekdate = new Date(nowdate-7*24*3600*1000);
        var y = oneweekdate.getFullYear();
        var m = oneweekdate.getMonth()+1;
        var d = oneweekdate.getDate();
        var formatwdate = y+'-'+m+'-'+d;
        $("#fdate").datebox("setValue",formatwdate);
        //获取系统前一个月的时间
        nowdate.setMonth(nowdate.getMonth()-1);
        var y = nowdate.getFullYear();
        var m = nowdate.getMonth()+1;
        var d = nowdate.getDate();
        var formatwdate = y+'-'+m+'-'+d;
        $("#fdate").datebox("setValue",formatwdate);
1

转换成年月日时分秒
function add0(m){return m<10?'0'+m:m }
    function timeFormat(timestamp){
    	  //timestamp是整数,否则要parseInt转换,不会出现少个0的情况
    	    var time = new Date(timestamp);
    	    var year = time.getFullYear();
    	    var month = time.getMonth()+1;
    	    var date = time.getDate();
    	    var hours = time.getHours();
    	    var minutes = time.getMinutes();
    	    var seconds = time.getSeconds();
    	    return year+'-'+add0(month)+'-'+add0(date)+' '+add0(hours)+':'+add0(minutes)+':'+add0(seconds);
    	}

//格式化日期  年月日
    function timeStamp2String(time){
        var datetime = new Date();
        datetime.setTime(time);
        var year = datetime.getFullYear();
        var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
        var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
        return year + "-" + month + "-" + date;
    }

你可能感兴趣的:(时间戳转化成年月日时分秒格式)