How to Format date using strftime() in Python ? Last Updated : 05 Dec, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we will see how to format date using strftime() in Python. localtime() and gmtime() returns a tuple representing a time and this tuple is converted into a string as specified by the format argument using python time method strftime(). Syntax: time.strftime(format[, sec]) sec: This is the time in number of seconds to be formatted. format: This is the directive or format code which would be used to format. Directive or format code Returned ValuedExample%YFull year with century2021,2022%yYear without century with zero padded value00,01,....21,22...,99%-yYear without century0,1...,99%mMonth with zero padded value01-12%-mMonth without zero padded value1-12%BFull month nameJanuary, February,..., December%bShort form of month Jan, Feb,...,Dec%AFull weekday nameSunday, Monday,..%aShort form of weekday nameSun, Mon,..%wWeekday as decimal value0-6%dDays with zero padded value01-31%-dDays with decimal value1-31%HHour (24-hour clock) as a zero-padded value.00-23%-HHour (24-hour clock) without zero-padded value.0,1,...,23%IHour (12-hour clock) as a zero-padded value.01-12%-IHour (12-hour clock) without zero-padded value.1-12%MMins with zero-padded 00-59%-MMins without zero padded value0-59%SSecs with zero padded value00-59%-SSecs without zero padded value0-59%fMicro Secs with zero-padded value000000 - 999999%pLocale’s AM or PM.AM/PM%jDay of the year with zero padded value001-366%-jDay of the year without zero padded value1-366%zUTC offset in the form +HHMM or -HHMM. %ZTime zone name. %CLocale’s appropriate date and timeFri Apr 02 02:09:07 2020%xLocale’s appropriate date02/04/22%XLocale’s appropriate time02:04:22%WWeek number of the year. Monday as first day of week00-53%UWeek number of the year. Sunday as first day of week00-53 Below are some examples for better understanding. Example 1: Python3 from datetime import datetime # current time and date # datetime object time = datetime.now() print("Without formatting:", time) # formatting date using strftime print("After formatting:", time.strftime("%b %d, %Y")) OutputWithout formatting: 2022-11-29 12:59:08.088819 After formatting: Nov 29, 2022 Output: Example 2: Python3 from datetime import datetime # current time and date # datetime object time = datetime.now() print("Without formatting:", time) # formatting date using strftime print("Year", time.strftime("%Y")) print("Month name", time.strftime("%B")) print("Day", time.strftime("%d")) Output: Example 3: Python3 from datetime import datetime # current time and date # datetime object time = datetime.now() # formatting date using strftime # format = MM/DD/YY print(time.strftime("%m/%d/%y")) # format = Month D, Yr print(time.strftime("%B %d, %Y")) # time formatting # HH:MM:SS print(time.strftime("%H:%M:%S")) Output: Comment More infoAdvertise with us Next Article How to change the Pandas datetime format in Python? M maheswaripiyush9 Follow Improve Article Tags : Python Python-datetime Practice Tags : python Similar Reads How to Get Current Date and Time using Python In this article, we will cover different methods for getting data and time using the DateTime module and time module in Python.Different ways to get Current Date and Time using PythonCurrent time using DateTime objectGet time using the time moduleGet Current Date and Time Using the Datetime ModuleIn 6 min read How to change the Pandas datetime format in Python? Prerequisites: Pandas The date-time default format is "YYYY-MM-DD". Hence, December 8, 2020, in the date format will be presented as "2020-12-08". The datetime format can be changed and by changing we mean changing the sequence and style of the format. Function used strftime() can change the date 1 min read How to Convert DateTime to UNIX Timestamp in Python ? Generating a UNIX timestamp from a DateTime object in Python involves converting a date and time representation into the number of seconds elapsed since January 1, 1970 (known as the Unix epoch). For example, given a DateTime representing May 29, 2025, 15:30, the UNIX timestamp is the floating-point 2 min read How to Print Specific date-time in Golang? Golang supports time formatting and parsing via pattern-based layouts. In Go, the current time can be determined by using time.Now(), provided by the time package. Package time provides functionality for measuring and displaying the time. To print Current date-time you need to import the "time" pack 2 min read How to add Days to a Date in Python? Python provides an in-built module datetime which allows easy manipulation and modification of date and time values. It allows arithmetic operations as well as formatting the output obtained from the DateTime module. The module contains various classes like date, time, timedelta, etc. that simulate 2 min read Get Current Time in different Timezone using Python Timezone is defined as a geographical area or region throughout which standard time is observed. It basically refers to the local time of a region or country. Most of the time zones are offset from Coordinated Universal Time (UTC), the world's standard for time zone. In order to get the current time 4 min read Like