"파이썬 사용자 함수"의 두 판 사이의 차이
DB CAFE
(→시간 초를 시:분:초로 계산(sec2time)) |
(→시간 포맷 변경 함수 sec2time) |
||
(같은 사용자의 중간 판 하나는 보이지 않습니다) | |||
20번째 줄: | 20번째 줄: | ||
return ('%d days, ' + pattern) % (d, h, m, s) | return ('%d days, ' + pattern) % (d, h, m, s) | ||
</source> | </source> | ||
+ | [[category:python]] |
2023년 2월 6일 (월) 21:42 기준 최신판
thumb_up 추천메뉴 바로가기
- DBA { Oracle DBA 명령어 > DBA 초급 과정 > DBA 고급 과정 }
- 튜닝 { 오라클 튜닝 목록 }
- 모델링 { 데이터 모델링 가이드 }
시간 포맷 변경 함수 sec2time[편집]
attach_file - 초(SEC)를 시:분:초로 포맷으로 표현 예제) 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)