mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/learning-system-mobile.git
synced 2025-12-07 01:46:44 +08:00
31 lines
1.3 KiB
JavaScript
31 lines
1.3 KiB
JavaScript
/**
|
|
* 表格时间格式化
|
|
*/
|
|
export function formatDate(cellValue) {
|
|
if (cellValue == null || cellValue == "") return "";
|
|
var date = new Date(cellValue)
|
|
var year = date.getFullYear()
|
|
var month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
|
|
var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
|
|
var hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
|
|
var minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
|
|
var seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
|
|
return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds
|
|
}
|
|
// 秒转时分秒
|
|
export function formatSeconds(value) {
|
|
let result = parseInt(value)
|
|
let h = Math.floor(result / 3600) < 10 ? '0' + Math.floor(result / 3600) : Math.floor(result / 3600);
|
|
let m = Math.floor((result / 60 % 60)) < 10 ? '0' + Math.floor((result / 60 % 60)) : Math.floor((result / 60 % 60));
|
|
let s = Math.floor((result % 60)) < 10 ? '0' + Math.floor((result % 60)) : Math.floor((result % 60));
|
|
|
|
let res = '';
|
|
if(h !== '00'){
|
|
res += `${h}小时`;
|
|
}
|
|
if(m !== '00' || h !== '00'){
|
|
res += `${m}分`;
|
|
}
|
|
res += `${s}秒`;
|
|
return res;
|
|
} |