标签:字符串转换 var func 显示日期 x11 console eof date() get
2014-04-23 18:55:49:123 日期格式
1398250549123 时间戳格式
前台显示日期格式,则
function tsToTime(ts) { var date = new Date(ts * 1000);//时间戳为10位需*1000,时间戳为13位的话不需乘1000 var Y = date.getFullYear() + ‘-‘; var M = (date.getMonth()+1 < 10 ? ‘0‘+(date.getMonth()+1) : date.getMonth()+1) + ‘-‘; var D = date.getDate() + ‘ ‘; var h = date.getHours() + ‘:‘; var m = date.getMinutes() + ‘:‘; var s = date.getSeconds(); return Y+M+D+h+m+s; } tsToTime(1403793804); console.log(tsToTime(1403793804));
var date = new Date(‘2018-11-28 02:47:30:097‘); // 有三种方式获取 var time1 = date.getTime(); var time2 = date.valueOf(); var time3 = Date.parse(date); console.log(time1); console.log(time2); console.log(time3);
标签:字符串转换 var func 显示日期 x11 console eof date() get
原文地址:https://www.cnblogs.com/anqiang1995/p/10034500.html