2019-07-26 13:32:43 +08:00
|
|
|
export function now() {
|
2019-11-04 18:41:58 +08:00
|
|
|
var d = new Date();
|
|
|
|
var year = d.getFullYear();
|
|
|
|
var month = change(d.getMonth() + 1);
|
|
|
|
var day = change(d.getDate());
|
|
|
|
var hour = change(d.getHours());
|
|
|
|
var minute = change(d.getMinutes());
|
|
|
|
var second = change(d.getSeconds());
|
|
|
|
function change(t) {
|
|
|
|
if (t < 10) {
|
|
|
|
return '0' + t;
|
|
|
|
} else {
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
|
2019-07-26 13:32:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export function timeFormat(usedTime) {
|
2019-11-04 18:41:58 +08:00
|
|
|
let hour = 0; let minute = 0; let second = 0; let sumTime = usedTime;
|
|
|
|
if (sumTime) {
|
|
|
|
if (sumTime >= 3600) {
|
|
|
|
hour = Math.floor(sumTime / 3600) % 24;
|
|
|
|
sumTime = (sumTime % 3600);
|
|
|
|
}
|
|
|
|
if (sumTime >= 60) {
|
|
|
|
minute = Math.floor(sumTime / 60);
|
|
|
|
sumTime = sumTime % 60;
|
|
|
|
}
|
|
|
|
second = Math.floor(sumTime);
|
|
|
|
}
|
|
|
|
function getTimeStr(val) {
|
|
|
|
return val < 10 ? '0' + val : val;
|
|
|
|
}
|
|
|
|
return getTimeStr(hour) + ':' + getTimeStr(minute) + ':' + getTimeStr(second);
|
2019-07-26 13:32:43 +08:00
|
|
|
}
|
|
|
|
|
2020-02-24 17:04:39 +08:00
|
|
|
// 时分秒转为时间戳
|
|
|
|
|
|
|
|
export function toTimeStamp(time) {
|
|
|
|
let s = 0;
|
|
|
|
let hour = time.split(':')[0];
|
|
|
|
let min = time.split(':')[1];
|
|
|
|
let sec = time.split(':')[2];
|
|
|
|
s = Number(hour * 3600) + Number(min * 60) + Number(sec);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 时间戳的只转为时分秒
|
|
|
|
|
|
|
|
export function formatDuring(mss) {
|
|
|
|
let hours = parseInt((mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
|
|
|
|
let minutes = parseInt((mss % (1000 * 60 * 60)) / (1000 * 60));
|
|
|
|
let seconds = (mss % (1000 * 60)) / 1000;
|
|
|
|
hours = hours < 10 ? ('0' + hours) : hours;
|
|
|
|
minutes = minutes < 10 ? ('0' + minutes) : minutes;
|
|
|
|
seconds = seconds < 10 ? ('0' + seconds) : seconds;
|
|
|
|
return hours + ":" + minutes + ":" + seconds;
|
|
|
|
}
|
|
|
|
|
2019-07-26 13:32:43 +08:00
|
|
|
export function prefixIntrger(num, length) {
|
2019-11-04 18:41:58 +08:00
|
|
|
return (Array(length).join('0') + num).slice(-length);
|
2019-08-02 10:36:17 +08:00
|
|
|
}
|