zoukankan      html  css  js  c++  java
  • 前端时间格式转换,js时间戳转时间(年-月-日 时:分:秒)

    做个笔记记录一下,希望大家有所帮助!

    var t=1521694261;
    timestampToTime(t)
    function timestampToTime(timestamp) {
        var date = new Date(timestamp * 1000); //时间戳为10位需*1000,时间戳为13位的话不需乘1000
        Y = date.getFullYear() + '-';
        M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
        D = change(date.getDate()) + ' ';
        h = change(date.getHours()) + ':';
        m = change(date.getMinutes()) + ':';
        s = change(date.getSeconds());
        return Y + M + D + h + m + s;
    }
    function change(t) {
        if (t < 10) {
            return "0" + t;
        } else {
            return t;
        }
    }
    原:科技改变生活!
  • 相关阅读:
    11.26
    数组
    JavaScript
    2018.11.26
    input标签
    HPH 函数
    jQuery
    19/1/3数组
    2018/12/26//循环体
    12/25
  • 原文地址:https://www.cnblogs.com/iyuanpeng/p/14329784.html
Copyright © 2011-2022 走看看