Python strftime()
import datetime
now = datetime.datetime.now()1) Format as βYYYY-MM-DDβ
2026-02-272) Format as βDD/MM/YYYYβ
27/02/20263) Format as βMonthName DD, YYYYβ
February 27, 20264) Format Date & 24h Time
5) Only Time (24-Hour)
6) Only Time (12-Hour)
7) Day of Week Name
8) Abbreviated Day of Week
9) Month as Number
10) Month Short Name
11) Month Full Name
12) Day of Year
13) ISO Week Number
14) Year Two-Digit
15) Zero-Padded Day & Month
16) Mixed Format
17) Full DateTime With Timezone
18) Show AM/PM Only
19) Include Weekday & Time
20) Custom Combined Format
π§ Helpful strftime Codes
strftime CodesFormat
Meaning
π Quick Example
π Tips for Students
Last updated