# 函数实现
const day = (day) => {
let ret = '';
switch (day) {
case 0:
ret = '';
break;
default:
ret = `${day}天`;
break;
}
return ret;
};
const hour = (hour) => {
let ret = '';
switch (hour) {
case 0:
ret = '';
break;
default:
ret = `${hour}小时`;
break;
}
return ret;
};
const minute = (value) => {
let ret = '';
switch (value) {
case 0:
ret = '';
break;
default:
ret = `${value}分钟`;
break;
}
return ret;
};
const second = (second) => {
let ret = '';
switch (second) {
case 0:
ret = '';
break;
default:
ret = `${second}秒`;
break;
}
return ret;
};
let funEnums = {
day: day,
hour: hour,
minute: minute,
second: second,
};
let funUnion = ['day', 'hour', 'minute', 'second'];
const appendTimeUnit = (obj) => {
if (!Object.keys(obj).length) {
return '-';
}
let ret = '';
for (var key in obj) {
funUnion.includes(key) ? (ret = ret + funEnums[key](obj[key])) : (ret = ret);
}
return ret;
};
export default appendTimeUnit;
# 函数使用
← 百度地图代码段 时间戳转换至天、时、分、秒 →