36 lines
810 B
JavaScript
36 lines
810 B
JavaScript
/**
|
|
* 将秒钟转为描述
|
|
*/
|
|
export function toDescriptionFromSecond(data) {
|
|
let seconds = data;
|
|
if (data instanceof String) {
|
|
seconds = parseInt(data)
|
|
}
|
|
let positive = true;
|
|
if (seconds < 0) {
|
|
positive =false;
|
|
seconds = -seconds;
|
|
}
|
|
|
|
let desc = {
|
|
day: parseInt(seconds / 86400),
|
|
hour: parseInt((seconds % 86400) / 3600),
|
|
minute: parseInt((seconds % 3600) / 60),
|
|
second: parseInt(seconds % 60),
|
|
positive: positive,
|
|
}
|
|
|
|
desc.text = `${positive ? '' : '-'} `;
|
|
if (desc.day > 0) {
|
|
desc.text += desc.day + ' 天 ';
|
|
}
|
|
if (desc.day > 0 || desc.hour > 0) {
|
|
desc.text += desc.hour + ' 时 ';
|
|
}
|
|
if (desc.day > 0 || desc.hour > 0 || desc.minute > 0) {
|
|
desc.text += desc.minute + ' 分 ';
|
|
}
|
|
desc.text += desc.second + ' 秒';
|
|
return desc;
|
|
}
|