python 的datetime.timedelta表示成可读的时间段,,def getWorkT


def getWorkTimeLength(ts):        totalSeconds = long(ts.total_seconds())        days = totalSeconds / (60*60*24)        hourSeconds = totalSeconds - days * (60*60*24)        hours = hourSeconds / 3600        minuteSeconds = hourSeconds - hours * 3600        minutes = minuteSeconds / 60        seconds = totalSeconds % 60        result = ''        if days > 0: result += str(days) + '天'        if hours > 0: result += str(hours) + '小时'        if minutes>0: result += str(minutes) + '分钟'        if seconds > 0: result += str(seconds) + '秒'        if not result: result = '小于1秒'        return result

评论关闭