chuanFE

时间戳精确转换为指定格式

月-日-时-分-秒

向getMonthDate方法传递时间戳参数,返回对应格式的时间

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
getMonthDate(time) {
var now = new Date(parseInt(time));
var year=now.getFullYear();
var month=now.getMonth()+1;
var date=now.getDate();
var hour=now.getHours();
var minute=now.getMinutes();
var second=now.getSeconds();
if (second < 10) {
second = "0" + second;
}
if (minute < 10) {
minute = "0" + minute;
}
return month+"-"+date+" "+hour+":"+minute+":"+second;
}

年-月-日-时-分-秒

向getFullTime方法传递时间戳参数,返回对应格式的时间

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
getFullTime(time) {
var now = new Date(parseInt(time));
var year=now.getFullYear();
var month=now.getMonth()+1;
var date=now.getDate();
var hour=now.getHours();
var minute=now.getMinutes();
var second=now.getSeconds();
if (second < 10) {
second = "0" + second;
}
if (minute < 10) {
minute = "0"+minute;
}
return year+"-"+month+"-"+date+" "+hour+":"+minute+":"+second;
}

我知道是不会有人点的,但万一有人想不开呢?