행위

"파이썬 사용자 함수"의 두 판 사이의 차이

DB CAFE

(새 문서: == 시간 초를 시:분:초로 계산(sec2time) == {{틀:투명 타이틀 |제목= - 예제) sec2time(초, 소수점 아래 표현갯수) }} <source lang=python> def sec2time(sec, n...)
(차이 없음)

2020년 4월 21일 (화) 17:31 판

thumb_up 추천메뉴 바로가기


시간 초를 시:분:초로 계산(sec2time)[편집]

틀:투명 타이틀 <source lang=python> def sec2time(sec, n_msec=3):

    Convert seconds to 'D days, HH:MM:SS.FFF' 
   if hasattr(sec,'__len__'):
       return [sec2time(s) for s in sec]
   m, s = divmod(sec, 60)
   h, m = divmod(m, 60)
   d, h = divmod(h, 24)
   if n_msec > 0:
       pattern = '%%02d:%%02d:%%0%d.%df' % (n_msec+3, n_msec)
   else:
       pattern = r'%02d:%02d:%02d'
   if d == 0:
       return pattern % (h, m, s)
   return ('%d days, ' + pattern) % (d, h, m, s)

</python>