zoneinfo는 Python 3.9+에서 IANA 시간대 데이터베이스를 사용하는 표준 모듈입니다. pytz 없이도 올바른 시간대 처리가 가능합니다.
언제 이 치트시트를 보나?
- 시간대가 있는 datetime을 다룰 때
- UTC ↔ 로컬 시간 변환이 필요할 때
- 서로 다른 시간대 간 변환이 필요할 때
핵심 사용법
| |
최소 예제
1. 기본 사용
| |
2. 시간대 변환
| |
3. UTC 시간 다루기
| |
4. 사용 가능한 시간대 목록
| |
5. naive → aware 변환
| |
6. DST (서머타임) 자동 처리
| |
7. 문자열 파싱과 시간대
| |
8. 시간 비교
| |
9. 날짜 연산
| |
10. tzdata 패키지 (Windows)
| |
주요 시간대 예시
| |
자주 하는 실수
1. naive datetime 비교
| |
2. replace vs astimezone 혼동
| |
한눈에 정리
| 작업 | 방법 |
|---|---|
| 시간대 객체 생성 | ZoneInfo("Asia/Seoul") |
| aware datetime | datetime(..., tzinfo=tz) |
| 현재 시간 | datetime.now(tz) |
| 시간대 변환 | dt.astimezone(new_tz) |
| 사용 가능 시간대 | available_timezones() |
![Featured image of post [Python Cheatsheet] 38. zoneinfo - 표준 시간대 (Python 3.9+)](/post/python-cheatsheet/datetime-standard-timezone-iana-zoneinfo-guide/wordcloud_hu_1c2e5f381f0aff7.webp)
![[Python Cheatsheet] 36. XML - ElementTree로 XML 파싱/생성](/post/python-cheatsheet/xml-elementtree-parse-edit-xpath-security-namespace-guide/wordcloud_hu_7317e644ad4bd8b8.webp)
![[Python Cheatsheet] 37. datetime - timezone/파싱/포맷](/post/python-cheatsheet/datetime-timezone-handling-utc-iso-format-parse-guide/wordcloud_hu_ed70821f7213c5c0.webp)
![[Python Cheatsheet] 38. zoneinfo - 표준 시간대 (Python 3.9+)](/post/python-cheatsheet/datetime-standard-timezone-iana-zoneinfo-guide/wordcloud_hu_beb337327e57cf73.webp)
![[Python Cheatsheet] 39. Regex - 안전하게 쓰는 최소 패턴](/post/python-cheatsheet/regex-safely-minimal-pattern-usage-tips-seo/wordcloud_hu_de92cb77e4ae189.webp)
![[Python Cheatsheet] 40. urllib.parse - URL 파싱과 조립](/post/python-cheatsheet/url-parse-build-encode-decode-guide-web-api-usage/wordcloud_hu_1ddf5f7257b096c5.webp)
![[Hardware] LattePanda Alpha에 Ubuntu 16.04 LTS 설치 가이드](/post/2018-12-06-install-ubuntu-16.04-on-lattepanda/wordcloud_hu_fc536f8de2cbd4bf.webp)
![[Rust] Comprehensive Rust 무료 강의 정리 및 코스 구조](/post/2022-12-30-comprehensive-rust/wordcloud_hu_d1420ff38434cdb6.webp)
![[Tutorial] Learn Prompting - 프롬프트 엔지니어링 무료 가이드 정리](/post/2022-12-30-learn-prompting/wordcloud_hu_6a9d105de4834753.webp)
![[Python Cheatsheet] 21. Enum & Flag - 열거형 실전 패턴](/post/python-cheatsheet/enum-flag-intenum-strenum-auto-bitwise-guide-best-patterns/wordcloud_hu_c5e80eb17669433.webp)
![[Python Cheatsheet] 29. operator - 연산자 함수와 효율적 접근자](/post/python-cheatsheet/efficient-operator-module-guide-for-sorting-functional-patterns/wordcloud_hu_ccfe1db60a2f866a.webp)