博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
时间戳格式化
阅读量:7060 次
发布时间:2019-06-28

本文共 827 字,大约阅读时间需要 2 分钟。

Date.prototype.format = function (fmt) {
var o = {
  "M+": this.getMonth() + 1, //月份
  "d+": this.getDate(), //日
  "h+": this.getHours(), //小时
  "m+": this.getMinutes(), //分
  "s+": this.getSeconds(), //秒
  "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  "S": this.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
  console.log("k="+k);
  console.log("fmt="+fmt);
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  return fmt;
}
 
console.log(eval( "/Date(1546473600000)/".replace(/\/Date\((\d+)\)\//gi, "new Date($1)"))); //Thu Jan 03 2019 08:00:00 GMT+0800 (中国标准时间)

转载于:https://www.cnblogs.com/yuyedaocao/p/10321132.html

你可能感兴趣的文章
hdu 3987(求割边最小的最小割)
查看>>
Android设备上的传感器模拟工具:SensorSimulator
查看>>
如何使用 SD 卡升级 XT788
查看>>
破解学习Asprise OCR v4.0 64位破解...仅供学习使用
查看>>
文件主文件学习 严蔚敏讲数据结构笔记27
查看>>
开源前端框架纵横谈
查看>>
让你的 Nginx 的 RTMP 直播具有统计某频道在线观看用户数量的功能
查看>>
Android-中常用方法集锦
查看>>
win 8 学习笔记一:生存周期
查看>>
Codeforces 55D Beautiful Number (数位统计)
查看>>
菜鸟学Java(三)——JSTL标签之核心标签
查看>>
hdu 3074 Multiply game(模板级线段树)
查看>>
MySQL: load data infile
查看>>
[转]HTML accesskey 属性
查看>>
I/O多路复用详解
查看>>
Linq使用Group By经验总结
查看>>
Ajax原生写法
查看>>
无线遥控器方案 Si4010/Si4012
查看>>
Hulu面试题
查看>>
On iPad, UIImagePickerController must be presented via UIPopoverController
查看>>