<script>
function CurentTime(nS) {
var now = new Date(nS); //获取时间
var date_time = Array(); //定义数组
var status = 0; //状态
var clock;
date_time.push(now.getFullYear()); //年
date_time.push(now.getMonth() + 1); //月
date_time.push(now.getDate()); //日
date_time.push(now.getHours()); //时
date_time.push(now.getMinutes()); //分
date_time.push(now.getSeconds()); //秒
do {
if (status > 0 && status <= 2) {//处理月日
if (date_time[status] < 10) {
clock += "0";
}
if (status < 2) {
str = '-';
} else {
str = ' ';
}
clock += date_time[status] + str;
} else if (status > 2 && status <= 5) {//处理时分秒
if (date_time[status] < 10) {
clock += "0";
}
if (status < 5) {
str = ':';
} else {
str = ' ';
}
clock += date_time[status] + str;
} else {//处理年
clock = date_time[status] + "-";
}
status++;
} while (status <= 5);
return clock;
}
var timestamp = (new Date()).valueOf();
alert(CurentTime(5521321654));
</script>
转载于:https://my.oschina.net/u/2601503/blog/610446