개발자 Q&A

개발하다 막혔다면? 여기서 질문하세요! 초보부터 고수까지, 함께 고민하고 해결하는 공간입니다. 누구나 자유롭게 질문하고 답변을 남겨보세요!

2025.05.23 16:11

timezone_identifiers_list와 pytz 모듈의 사용법에 대해 질문합니다.

목록
  • DP전문가 12일 전 2025.05.23 16:11 인기
  • 163
    1
저는 현재 시간대 관련 문제로 어려움을 겪고 있습니다.
timezone_identifiers_list는 시간대 이름 목록을 반환하는 데 사용됩니다.
하지만 pytz 모듈의 사용법을 제대로 이해하지 못해 시간대 이름을 지정할 때 오류가 발생합니다.

다음은 코드 예시입니다.

python

import pytz



timezone_identifiers_list = pytz.common_timezones

print(timezone_identifiers_list)



이 코드는 모든 시간대 이름을 출력합니다. 하지만 특정 시간대 이름을 지정할 때 오류가 발생합니다.

다음은 코드 예시입니다.

python

from datetime import datetime

import pytz



seoul = pytz.timezone('Asia/Seoul')

now = datetime.now(seoul)

print(now.strftime('%Y-%m-%d %H:%M:%S'))



위 코드는 현재 서울 시간을 출력합니다. 하지만 'Asia/Seoul' 시간대 이름이 timezone_identifiers_list에 포함되어 있는지 확인하고 싶습니다.

따라서 timezone_identifiers_list에 'Asia/Seoul' 시간대 이름이 포함되어 있는지 확인하고, 포함되어 있지 않다면 'Asia/Seoul' 시간대 이름이 timezone_identifiers_list에 포함되어 있는지 확인하도록 도와주세요.

    댓글목록

    profile_image
    나우호스팅  12일 전



    pytz 모듈은 시간대 이름을 지정할 때 사용하는 tzinfo 객체를 반환합니다. timezone_identifiers_list는 시간대 이름 목록을 반환하는 데 사용됩니다.

    이러한 경우, 시간대 이름을 지정할 때 오류가 발생하는 이유는 timezone_identifiers_list에 시간대 이름이 포함되어 있지 않기 때문입니다.

    따라서 timezone_identifiers_list에 'Asia/Seoul' 시간대 이름이 포함되어 있는지 확인하려면 다음과 같이 코드를 작성할 수 있습니다.

    #hostingforum.kr
    python
    
    import pytz
    
    
    
    timezone_identifiers_list = pytz.common_timezones
    
    print('시간대 이름 목록:')
    
    print(timezone_identifiers_list)
    
    
    
    if 'Asia/Seoul' in timezone_identifiers_list:
    
        print("'Asia/Seoul' 시간대 이름이 포함되어 있습니다.")
    
    else:
    
        print("'Asia/Seoul' 시간대 이름이 포함되어 있지 않습니다.")
    
    


    위 코드를 실행하면 'Asia/Seoul' 시간대 이름이 포함되어 있는지 확인할 수 있습니다.

    만약 'Asia/Seoul' 시간대 이름이 포함되어 있지 않다면, timezone_identifiers_list에 포함되어 있는지 확인할 수 있습니다.

    #hostingforum.kr
    python
    
    import pytz
    
    
    
    timezone_identifiers_list = pytz.common_timezones
    
    print('시간대 이름 목록:')
    
    print(timezone_identifiers_list)
    
    
    
    if 'Asia/Seoul' in timezone_identifiers_list:
    
        print("'Asia/Seoul' 시간대 이름이 포함되어 있습니다.")
    
    else:
    
        print("'Asia/Seoul' 시간대 이름이 포함되어 있지 않습니다. 포함되어 있는 시간대 이름 목록:")
    
        for tz in timezone_identifiers_list:
    
            if 'Seoul' in tz:
    
                print(tz)
    
    


    위 코드를 실행하면 'Asia/Seoul' 시간대 이름이 포함되어 있지 않다면, 포함되어 있는 시간대 이름 목록을 출력할 수 있습니다.

    2025-05-23 16:12

  • 개발자 Q&A 포인트 정책
      글쓰기
      50P
      댓글
      10P
  • 전체 25,282건 / 100 페이지

검색

게시물 검색