"파이썬 사용자 함수"의 두 판 사이의 차이
DB CAFE
(새 문서: == 시간 초를 시:분:초로 계산(sec2time) == {{틀:투명 타이틀 |제목= - 예제) sec2time(초, 소수점 아래 표현갯수) }} <source lang=python> def sec2time(sec, n...) |
(→시간 초를 시:분:초로 계산(sec2time)) |
||
19번째 줄: | 19번째 줄: | ||
return pattern % (h, m, s) | return pattern % (h, m, s) | ||
return ('%d days, ' + pattern) % (d, h, m, s) | return ('%d days, ' + pattern) % (d, h, m, s) | ||
− | </ | + | </source> |
2020년 4월 21일 (화) 17:32 판
thumb_up 추천메뉴 바로가기
- DBA { Oracle DBA 명령어 > DBA 초급 과정 > DBA 고급 과정 }
- 튜닝 { 오라클 튜닝 목록 }
- 모델링 { 데이터 모델링 가이드 }
시간 초를 시:분:초로 계산(sec2time)[편집]
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)