■ datetime 클래스의 fromtimestamp 메소드를 사용해 struct_time 객체에서 datetime 객체를 구하는 방법을 보여준다.
▶ 예제 코드 (PY)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import time from datetime import datetime sourceDatetime = datetime.now() sourceStructTime = sourceDatetime.timetuple() sourceTimestamp = time.mktime(sourceStructTime) targetDatetime = datetime.fromtimestamp(sourceTimestamp) print(sourceDatetime ) print(sourceStructTime) print(targetDatetime ) """ 2024-06-17 21:00:11.827053 time.struct_time(tm_year=2024, tm_mon=6, tm_mday=17, tm_hour=21, tm_min=0, tm_sec=11, tm_wday=0, tm_yday=169, tm_isdst=-1) 2024-06-17 21:00:11 """ |