根据秒生成 x天x时x分 的字符串

版权声明:转载请注明出处 https://blog.csdn.net/wang_8101/article/details/81334871

groovy实现:

/**
* 该方法的入参为秒
*/
getOnlineDescription(Long onlineSec) {
    def day = Math.floor(onlineSec / 86400).toInteger()
    def temponline = onlineSec % 86400 // 若入参为毫秒,86400后加三个0
    def hour = Math.floor(temponline / 3600).toInteger()
    def temponline2 = temponline % 3600
    def min = Math.floor(temponline2 / 60).toInteger()
    def re = ''
    if (day > 0) {
        re = day + "天"
    }
    if (day + hour > 0) {
        re += hour + "小时"
    }
    if (day + hour + min > 0) {
        re += min + "分钟"
    }
    re
}

猜你喜欢

转载自blog.csdn.net/wang_8101/article/details/81334871