时间戳和时间格式之间的转换

时间戳和时间格式之间的转换

1.时间转时间戳

// 返回自定义时间戳
 Date.parse("2017/03/19")

2.时间戳转时间

var date = new Date(1398250549490);
Y = date.getFullYear() + '-';
M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
D = date.getDate() + ' ';
h = date.getHours() + ':';
m = date.getMinutes() + ':';
s = date.getSeconds(); 
console.log(Y+M+D+h+m+s); 
// 输出结果:2014-04-23 18:55:49

猜你喜欢

转载自blog.csdn.net/chb19991118/article/details/121510610