【JS】 JS毫秒值转化为正常格式 或者正常格式转化为毫秒值

1.毫秒值转化为正常时间格式  最简单的方法

new Date(后台传来的毫秒值).toLocaleDateString()

就是这个样子

2.毫秒值转化为自定义的时间格式

本页面重写一下  toLocaleString()方法

Date.prototype.toLocaleString = function() {
          return this.getFullYear() + "年" + (this.getMonth() + 1) + "月" + this.getDate() + "日 " + this.getHours() + "点" + this.getMinutes() + "分" + this.getSeconds() + "秒";
    };

3.正常的时间格式 转化为毫秒值

(new Date("2011/11/11 20:10:10")).getTime()
原文地址:https://www.cnblogs.com/sxdcgaq8080/p/6364972.html