<html>
<head>
<title>时间戳转化为年月日时分秒</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
</body>
</html>
<script>
window.onload=function(){
var now=new Date();//当前系统时间
var shijianchuo = now.getTime();//获取当前时间戳
alert("时间戳:"+shijianchuo);
var nowdate = new Date(shijianchuo);//将时间戳转化为日期对象
var nowtime=nowdate.Format("yyyy-MM-dd hh:mm:ss");//格式化当前系统时间,相当于将时间戳转化为年月日时分秒了
alert("当前时间:"+nowtime);
}
/*
日期格式化:
对Date的扩展,将 Date 转化为指定格式的String
年(y)可以用1-4个占位符,季度(q)可以用1-2个占位符.
月(M)、日(d)、小时(h)、分(m)、秒(s)可以用1-2个占位符.
毫秒(S)只能用1个占位符(是1-3位的数字)
例子:
(new Date()).Format("yyyy-MM-dd hh:mm:ss.S")
(new Date()).Format("yyyy-MM-dd hh:mm:ss.S毫秒 第qq季度")
*/
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)
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;
}
</script>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有