Python에서 epoch 형식을 struct_time 객체로 변환하기
epoch 형식에서 얻은 초(seconds)는
특별한 객체 struct_time으로
변환할 수 있습니다.
데이터 구조 측면에서 이 객체는 사전과 유사합니다.
객체 struct_time은 epoch에 저장된
날짜를 더 편리하게 작업하기 위해 필요합니다.
이제 struct_time 객체를 얻어봅시다:
now = time.time()
res = time.localtime(now)
print(res)
코드 실행 결과:
time.struct_time(tm_year=2025, tm_mon=12,
tm_mday=31, tm_hour=15, tm_min=40, tm_sec=51, tm_wday=3,
tm_yday=365, tm_isdst=0)
이제 struct_time에서
현재 월을 얻어봅시다. 이를 위해 res 변수의
tm_mon 속성에 점(.)을 통해 접근합니다:
print(res.tm_mon) # 12를 출력합니다
struct_time에서 현재
일(day)을 출력하세요.
struct_time에서 현재
시간(hour)을 출력하세요.
다음 epoch 값이 주어졌습니다:
dt = 1602314100.0
이로부터 struct_time을 얻으세요.