js 时间戳格式话
来源:互联网 发布:淘宝 布料 编辑:程序博客网 时间:2024/06/17 09:08
<meta charset="utf-8" />
<head>
</head>
<body>
<script type="text/javascript">
Date.prototype.format = function(format)
{
var o =
{
"M+" : this.getMonth()+1, //month
"d+" : this.getDate(), //day
"h+" : this.getHours(), //hour
"m+" : this.getMinutes(), //minute
"s+" : this.getSeconds(), //second
"q+" : Math.floor((this.getMonth()+3)/3), //quarter
"S" : this.getMilliseconds() //millisecond
}
if(/(y+)/.test(format))
{
format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
}
for(var k in o)
{
if(new RegExp("("+ k +")").test(format))
{
format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
}
}
return format;
}
var testDate = new Date( 1383734177000 );//这里必须是整数,毫秒
var testStr = testDate.format("yyyy年MM月dd日hh小时mm分ss秒");
var testStr2 = testDate.format("yyyy-MM-dd");
alert(testStr + " " + testStr2);
</script>
</body>
</html>
==================================
第二中方法
//时间格式化
Date.prototype.format = function(format)
{
var o =
{
"M+" : this.getMonth()+1, //month
"d+" : this.getDate(), //day
"h+" : this.getHours(), //hour
"m+" : this.getMinutes(), //minute
"s+" : this.getSeconds(), //second
"q+" : Math.floor((this.getMonth()+3)/3), //quarter
"S" : this.getMilliseconds() //millisecond
}
if(/(y+)/.test(format))
{
format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
}
for(var k in o)
{
if(new RegExp("("+ k +")").test(format))
{
format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
}
}
return format;
}
var time = new Date(data[i].time*1000);//这里必须是整数,毫秒
var timestr = time.format("yyyy-MM-dd");
- js 时间戳格式话
- js时间戳-------日期格式
- js时间戳格式化成日期格式
- js时间戳转成时间格式
- JS将时间戳转换时间格式
- JS 时间戳转换成时间格式
- js时间戳(时间格式转换)
- js 封装时间戳为时间格式
- js时间戳转为日期格式
- js时间戳怎么转成日期格式
- js时间戳转为日期格式
- js时间戳怎么转成日期格式
- js时间戳转为日期格式
- js时间戳怎么转成日期格式
- js内时间戳日期格式转化
- JS中将时间戳转格式
- js时间戳怎么转成日期格式
- js时间戳转日期格式
- 黑马程序员_交通灯管理系统
- web建站--django
- Gray Code
- mysql安装图解
- JavaScript 获取浏览器信息
- js 时间戳格式话
- socket实现广播和客户端到客户端的通信
- 知识-冯诺伊曼体系
- 安卓开发中,启动4.+的模拟器慢,解决办法。
- iOS界面设计规范
- A Tutorial on the Device Tree
- android-【DDMS->heap】工具-内存检测工具(内存泄露的检测工具)
- iOS AutoLayout 编码
- 云操作系统,是真的吗?(译文)