반응형
Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- gas
- 파이썬
- string
- PANDAS
- Redshift
- matplotlib
- SQL
- Presto
- PySpark
- google apps script
- Tkinter
- numpy
- Kotlin
- dataframe
- Google Excel
- GIT
- Java
- list
- Apache
- Github
- c#
- math
- django
- Python
- PostgreSQL
- hive
- Google Spreadsheet
- Excel
- array
Archives
- Today
- Total
달나라 노트
Python datetime : utcnow (UTC.Python UTC, 시스템 시간 상관없이 UTC 추출하기. 협정 세계 표준시.) 본문
Python/Python datetime
Python datetime : utcnow (UTC.Python UTC, 시스템 시간 상관없이 UTC 추출하기. 협정 세계 표준시.)
CosmosProject 2021. 10. 28. 02:14728x90
반응형
Python의 datetime library에는 utcnow라는 method가 있는데 이것은 현재 기준 UTC를 반환해줍니다.
import datetime
dt_utc = datetime.datetime.utcnow()
print(dt_utc)
-- Result
2021-10-27 17:08:51.097881
사용법은 상당히 간단합니다.
utcnow() method만으로 UTC를 얻을 수 있습니다.
utcnow()는 Python코드를 실행하는 서버나 컴퓨터의 시간에 상관없이 UTC값을 기준으로 계산되는 것이므로,
혹시나 컴퓨터의 시간이 이상하다거나 사용하는 서버의 시간이 이상할 경우 정확한 현재 시간/날짜를 얻기 위해 사용할 수 있습니다.
import datetime
dt_kst = datetime.datetime.utcnow() + datetime.timedelta(hours=9)
print(dt_kst)
-- Result
2021-10-28 02:08:51.098113
한국 표준시인 KST는 UTC로부터 9시간을 더하면 되므로,
위처럼 utcnow에 9시간을 더하도록 코드를 작성하면 KST를 얻을 수도 있습니다.
728x90
반응형
'Python > Python datetime' 카테고리의 다른 글
| Python datetime : weekday, isoweekday (week day number 요일번호 추출) (0) | 2021.03.27 |
|---|---|
| Python datetime : isocalendar, strftime('%U'), strftime('%W') (week number 추출) (0) | 2020.12.23 |
| Python datetime : strftime(시간 날짜 데이터를 텍스트로) & strptime(텍스트를 시간 날짜 데이터로) (0) | 2020.12.23 |
| Python datetime : timedelta(시간 또는 날짜의 차이) (0) | 2020.12.23 |
| Python datetime : now(현재 날짜와 시간) & today(현재 날짜) (0) | 2020.12.23 |
Comments
