时间转换:秒转分,秒转时分,秒转时分秒

110 阅读1分钟
/**
 * @description: 秒转时分
 */
export function timeCycle(second) {
  let h = parseInt(second/3600)
  let m = parseInt(second/60%60)
  return `${h> 0 ? `${h}h` : ''}${m>0 ? `${m}min` : ''}`
}

/**
 * @description: 秒转时分秒
 */
export function timeCycleTo(second) {
  let h = parseInt(second/3600)
  let m = parseInt(second/60%60)
  let s = Math.ceil(second%60)>59 ? 59 : Math.ceil(second%60)
  return `${h> 0 ? `${h}h` : ''}${m>0 ? `${m}min` : ''}${s}s`
  // return `${(h-0 )> 0 ? `${h}h` : ''}${m<10 ? '0'+m : m}m${s < 10 ? '0' + s : s}s`
} 
/**
 * @description: 秒转时分
 */
export function toTimeCycle(second) {
  let h = parseInt(second/3600)
  let m = parseInt(second/60%60)
  return `${h> 0 ? `${h}h` : ''} ${m>0 ? `${m}min` : ''}`
}