输入:2019-6-18 18:16
输出:时间戳(单位为秒)
DateToUnix: function(str) {
var f = str.split(' ', 2);
var d = (f[0] ? f[0] : '').split('-', 3);
var t = (f[1] ? f[1] : '').split(':', 2);
return (new Date(
parseInt(d[0], 10) || null,
(parseInt(d[1], 10) || 1) - 1,
parseInt(d[2], 10) || null,
parseInt(t[0], 10) || null,
parseInt(t[1], 10) || null,
// parseInt(t[2], 10) || null
)).getTime() / 1000;
},
//将秒数转换为天,时,分,秒
输入:15245s
输出:x天x小时x分x秒
secToTime: function(time) {
var d = parseInt(time / 43200);
time = time % 43200;
var h = parseInt(time / 3600);
time = time % 3600;
var m = parseInt(time / 60);
var s = time % 60;
if (d < 10) d = "0" + d;
if (h < 10) h = "0" + h;
if (m < 10) m = "0" + m;
if (s < 10) s = "0" + s;
var str = d + "天" + h + "小时" + m + "分" + s + "秒";
return str;
},