-
[Python/Module] Datetime코딩/Python 2022. 12. 21. 17:31728x90
Python Dates
- 날짜, 시간은 파이썬에 포함되지 않음
- 'datetime' 모듈 사용
import datetime x = datetime.datetime.now() y = datetime.datetime(2020, 5, 17) # object from datetime() class z = datetime.datetime(2018, 6, 1) print(x) # 2022-12-16 15:33:49.473356 print(x.year) # 2022 print(x.strftime("%A")) # Friday print(y) # 2020-05-17 00:00:00 print(x.strftime("%B")) # June
Date Output
2022-12-16 15:30:04.284752: year, month, day, hour, minute, second, and microsecond
Creating Date Objects
- datetime() class (constructor)
The
strftime()
Method- formatting date objects
A reference of all the legal format codes
Directive Description Example %a Weekday, short version Wed %A Weekday, full version Wednesday %w Weekday as a number 0-6, 0 is Sunday 3 %d Day of month 01-31 31 %b Month name, short version Dec %B Month name, full version December %m Month as a number 01-12 12 %y Year, short version, without century 18 %Y Year, full version 2018 %H Hour 00-23 17 %I Hour 00-12 05 %p AM/PM PM %M Minute 00-59 41 %S Second 00-59 08 %f Microsecond 000000-999999 548513 %z UTC offset +0100 %Z Timezone CST %j Day number of year 001-366 365 %U Week number of year, Sunday as the first day of week, 00-53 52 %W Week number of year, Monday as the first day of week, 00-53 52 %c Local version of date and time Mon Dec 31 17:41:00 2018 %C Century 20 %x Local version of date 12/31/18 %X Local version of time 17:41:00 %% A % character % %G ISO 8601 year 2018 %u ISO 8601 weekday (1-7) 1 %V ISO 8601 weeknumber (01-53) 01 728x90'코딩 > Python' 카테고리의 다른 글
[Python tutorial] 28. Reference (0) 2022.12.21 [Python tutorial] 27. Exception (0) 2022.12.21 [Python tutorial] 26. Keyword (0) 2022.12.21 [Python tutorial] 25. File Methods (0) 2022.12.21 [Python tutorial] 24. Set Methods (0) 2022.12.21