관리 메뉴

JIHYUN JEONG

[파이썬/Python] datetime, pytz 모듈 (timezone Asia Seoul 타임존 서울) 현재시간으로 하기 본문

Information Technology/Python

[파이썬/Python] datetime, pytz 모듈 (timezone Asia Seoul 타임존 서울) 현재시간으로 하기

StopHyun 2019. 12. 1. 18:05

 

datetime, pytz 모듈 을 활용하여 timezone Asia Seoul 타임존 서울 기준으로 현재시간을 활용해보겠습니다.

 

 

1
2
3
4
5
6
7
8
import datetime
from pytz import timezone
 
time_now = datetime.datetime.now(timezone('Asia/Seoul'))
print(time_now)
 
time_now_str = str(time_now)
print(time_now_str[:19])
cs

혹시나 현재 시간이 길다면 아래처럼 문자열로 해당 시,분,초 까지 슬라이스 해서 쓸 수 도 있습니다.

 

Comments