js将php时间戳转换成格式化日期

    //js将php时间戳转换成格式化日期
    function to_date(phpstr) {
        str = parseInt(phpstr) * 1000;//将php时间戳转化为整形并乘以1000
        var newDate = new Date(str);
        var year = newDate.getUTCFullYear();//取年份
        var month = newDate.getUTCMonth() + 1;//取月份
        var nowday = newDate.getUTCDate();//取天数
        var hours = newDate.getHours();//取小时
        var minutes = newDate.getMinutes();//取分钟
        var seconds = newDate.getSeconds();//取秒
        return year + "-" + month + "-" + nowday + " " + hours + ":" + minutes + ":" + seconds;//拼接 2017-2-21 12:23:43    }

    }

 

你可能感兴趣的:(js,php)