Home > Backend Development > PHP Tutorial > javascript - How to convert js timestamp to time format

javascript - How to convert js timestamp to time format

WBOY
Release: 2016-09-12 17:44:47
Original
1164 people have browsed it

从数据库中取得值 时间戳是秒

javascript - How to convert js timestamp to time format
发现显示的都是1970年

回复内容:

从数据库中取得值 时间戳是秒

javascript - How to convert js timestamp to time format
发现显示的都是1970年

时间戳的单位是毫秒

如果obj.create_time是秒,那应该是obj.create_time * 1000

<code>//设定时间格式化函数
    Date.prototype.format = function (format) {
        var args = {
            "M+": this.getMonth() + 1,
            "d+": this.getDate(),
            "h+": this.getHours(),
            "m+": this.getMinutes(),
            "s+": this.getSeconds(),
        };
        if (/(y+)/.test(format))
            format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var i in args) {
            var n = args[i];
            if (new RegExp("(" + i + ")").test(format))
                format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? n : ("00" + n).substr(("" + n).length));
        }
        return format;
    };</code>
Copy after login

使用:new Date(time).format("yyyy-MM-dd")

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template