47 lines
1.0 KiB
JavaScript
47 lines
1.0 KiB
JavaScript
|
export function now() {
|
||
|
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
|
||
|
}
|
||
|
|
||
|
export function timeFormat(time) {
|
||
|
function getTimeStr(val) {
|
||
|
return val < 10 ? '0' + val : val
|
||
|
}
|
||
|
|
||
|
if (Number.isInteger(time)) {
|
||
|
let hour = 0; let minute = 0; let second = 0
|
||
|
if (time) {
|
||
|
if (time >= 3600) {
|
||
|
hour = Math.floor(time / 3600) % 24
|
||
|
time = (time % 3600)
|
||
|
}
|
||
|
if (time >= 60) {
|
||
|
minute = Math.floor(time / 60)
|
||
|
time = time % 60
|
||
|
}
|
||
|
second = Math.floor(time)
|
||
|
}
|
||
|
|
||
|
return getTimeStr(hour) + ':' + getTimeStr(minute) + ':' + getTimeStr(second)
|
||
|
} else {
|
||
|
return ''
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export function prefixIntrger(num, length) {
|
||
|
return (Array(length).join('0') + num).slice(-length)
|
||
|
}
|