一个将Unix时间转换为通用时间的工具
演示效果:
点击转换之后变为:
源代码:
function calctime2(){
var time = window.document.getElementById("inpTime").value;
if ( time == "" )
{
alert("时间为空,请重新输入");
return;
}
if ( isDigit(time) == false )
{
alert("时间只能由数字组成");
return;
}
document.write( millisecondsStrToDate( time * 1000 ));
}
function isDigit(s) {
var patrn=/^[0-9]{1,20}$/;
if (!patrn.exec(s)) return false
return true
}
function millisecondsStrToDate(str){
var startyear = 1970;
var startmonth = 1;
var startday = 1;
var d , s;
var sep = ":";
d = new Date();
d.setFullYear( startyear , startmonth , startday );
d.setTime(0);
d.setMilliseconds(str);
s = d.getYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate() + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();
//alert( d.toLocaleString());
return d.toLocaleString();
}
原文地址:http://blog.csdn.net/deadwalk/article/details/44318021