Python
[Python] 현재 시간 출력하기
teamnova
2022. 7. 19. 12:00
728x90
현재 시간을 알아야 할 때 형식에 맞춰진 데이터를 함수화 하여 사용하는것이 좋습니다.
이번 시간에는 파이썬에서 현재 시간을 가져오는 방법을 알아보겠습니다.
def now_time():
# 현재 시간 구하기용
now = datetime.now(timezone('Asia/Seoul')) # 한국시간
now_time = str(now.year) + "-" + str(now.month) + "-" + str(now.day) + "_" + str(now.hour) + "-" + \
str(now.minute) + "-" + str(now.second)
now_time = now.strftime("%Y/%m/%d %H:%M:%S")
return now_time
now_time 이라는 함수를 사용하면 현재 시간을 가져 올 수 있습니다.
timezone에서 국가별 기준 시간을 설정 할 수 있습니다.