본문 바로가기
파이썬

파이썬 Python의 시간대 이름에서 UTC 오프셋 가져 오기

by º기록 2020. 10. 5.
반응형

파이썬의 시간대 이름에서 UTC 오프셋을 어떻게 얻을 수 있습니까?

예 : 아시아 / 예루살렘 이 있고 +0200 을 받고 싶습니다.

 

해결 방법

 

DST (일광 절약 시간) 때문에 결과는 연중 시간에 따라 다릅니다.

import datetime, pytz

datetime.datetime.now(pytz.timezone('Asia/Jerusalem')).strftime('%z')

# returns '+0300' (because 'now' they have DST)


pytz.timezone('Asia/Jerusalem').localize(datetime.datetime(2011,1,1)).strftime('%z')

# returns '+0200' (because in January they didn't have DST)

 

참조 페이지 https://stackoverflow.com/questions/5537876

 

 

반응형

댓글