date time strftime

# Example usage:
import datetime
date_time = datetime.datetime.now()
print(date_time)
--> '2020-10-03 15:29:54.822751'

# From the date_time variable, you can extract the date in various
# custom formats with .strftime(), for example:
date_time.strftime("%d/%m/%Y")
--> '03/10/2020' # dd/mm/yyyy

date_time.strftime("%m/%d/%y")
--> '10/03/20' # mm/dd/yy

date_time.strftime("%Y/%m/%d")
--> '2020/10/03'

date_time.strftime("%Y-%m-%d")
--> '2020-10-03'

date_time.strftime("%B %d, %Y")
--> 'October 03, 2020'

# Key for other custom date/time formats:
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 00-53				52	
%c			Local version of date and time			Mon Dec 31 17:41:00 2018	
%x			Local version of date					12/31/18	
%X			Local version of time					17:41:00	
%%			A % character							%

0
7
Mcdoty 160 points

                                    
from datetime import datetime

timestamp = 1528797322
date_time = datetime.fromtimestamp(timestamp)

print("Date time object:", date_time)

d = date_time.strftime("%m/%d/%Y, %H:%M:%S")
print("Output 2:", d)	

d = date_time.strftime("%d %b, %Y")
print("Output 3:", d)

d = date_time.strftime("%d %B, %Y")
print("Output 4:", d)

d = date_time.strftime("%I%p")
print("Output 5:", d)

0
0
0
0
Mcdoty 160 points

                                    
from datetime import datetime

timestamp = 1528797322
date_time = datetime.fromtimestamp(timestamp)

print("Date time object:", date_time)

d = date_time.strftime("%m/%d/%Y, %H:%M:%S")
print("Output 2:", d)	

d = date_time.strftime("%d %b, %Y")
print("Output 3:", d)

d = date_time.strftime("%d %B, %Y")
print("Output 4:", d)

d = date_time.strftime("%I%p")
print("Output 5:", d)

0
0
0
0
Mcdoty 160 points

                                    
from datetime import datetime

timestamp = 1528797322
date_time = datetime.fromtimestamp(timestamp)

print("Date time object:", date_time)

d = date_time.strftime("%m/%d/%Y, %H:%M:%S")
print("Output 2:", d)	

d = date_time.strftime("%d %b, %Y")
print("Output 3:", d)

d = date_time.strftime("%d %B, %Y")
print("Output 4:", d)

d = date_time.strftime("%I%p")
print("Output 5:", d)

0
0
0
0
Mcdoty 160 points

                                    
from datetime import datetime

timestamp = 1528797322
date_time = datetime.fromtimestamp(timestamp)

print("Date time object:", date_time)

d = date_time.strftime("%m/%d/%Y, %H:%M:%S")
print("Output 2:", d)	

d = date_time.strftime("%d %b, %Y")
print("Output 3:", d)

d = date_time.strftime("%d %B, %Y")
print("Output 4:", d)

d = date_time.strftime("%I%p")
print("Output 5:", d)

0
0
0
0
Mcdoty 160 points

                                    
from datetime import datetime

timestamp = 1528797322
date_time = datetime.fromtimestamp(timestamp)

print("Date time object:", date_time)

d = date_time.strftime("%m/%d/%Y, %H:%M:%S")
print("Output 2:", d)	

d = date_time.strftime("%d %b, %Y")
print("Output 3:", d)

d = date_time.strftime("%d %B, %Y")
print("Output 4:", d)

d = date_time.strftime("%I%p")
print("Output 5:", d)

0
0
0
0
Mcdoty 160 points

                                    
from datetime import datetime

timestamp = 1528797322
date_time = datetime.fromtimestamp(timestamp)

print("Date time object:", date_time)

d = date_time.strftime("%m/%d/%Y, %H:%M:%S")
print("Output 2:", d)	

d = date_time.strftime("%d %b, %Y")
print("Output 3:", d)

d = date_time.strftime("%d %B, %Y")
print("Output 4:", d)

d = date_time.strftime("%I%p")
print("Output 5:", d)

0
0
0
0
Mcdoty 160 points

                                    
from datetime import datetime

timestamp = 1528797322
date_time = datetime.fromtimestamp(timestamp)

print("Date time object:", date_time)

d = date_time.strftime("%m/%d/%Y, %H:%M:%S")
print("Output 2:", d)	

d = date_time.strftime("%d %b, %Y")
print("Output 3:", d)

d = date_time.strftime("%d %B, %Y")
print("Output 4:", d)

d = date_time.strftime("%I%p")
print("Output 5:", d)

0
0
0
0
Mcdoty 160 points

                                    
from datetime import datetime

timestamp = 1528797322
date_time = datetime.fromtimestamp(timestamp)

print("Date time object:", date_time)

d = date_time.strftime("%m/%d/%Y, %H:%M:%S")
print("Output 2:", d)	

d = date_time.strftime("%d %b, %Y")
print("Output 3:", d)

d = date_time.strftime("%d %B, %Y")
print("Output 4:", d)

d = date_time.strftime("%I%p")
print("Output 5:", d)

0
0
0
0
Mcdoty 160 points

                                    
from datetime import datetime

timestamp = 1528797322
date_time = datetime.fromtimestamp(timestamp)

print("Date time object:", date_time)

d = date_time.strftime("%m/%d/%Y, %H:%M:%S")
print("Output 2:", d)	

d = date_time.strftime("%d %b, %Y")
print("Output 3:", d)

d = date_time.strftime("%d %B, %Y")
print("Output 4:", d)

d = date_time.strftime("%I%p")
print("Output 5:", d)

0
0
0
0
Mcdoty 160 points

                                    
from datetime import datetime

timestamp = 1528797322
date_time = datetime.fromtimestamp(timestamp)

print("Date time object:", date_time)

d = date_time.strftime("%m/%d/%Y, %H:%M:%S")
print("Output 2:", d)	

d = date_time.strftime("%d %b, %Y")
print("Output 3:", d)

d = date_time.strftime("%d %B, %Y")
print("Output 4:", d)

d = date_time.strftime("%I%p")
print("Output 5:", d)

0
0
0
0
Mcdoty 160 points

                                    
from datetime import datetime

timestamp = 1528797322
date_time = datetime.fromtimestamp(timestamp)

print("Date time object:", date_time)

d = date_time.strftime("%m/%d/%Y, %H:%M:%S")
print("Output 2:", d)	

d = date_time.strftime("%d %b, %Y")
print("Output 3:", d)

d = date_time.strftime("%d %B, %Y")
print("Output 4:", d)

d = date_time.strftime("%I%p")
print("Output 5:", d)

0
0
0
0
Mcdoty 160 points

                                    
from datetime import datetime

timestamp = 1528797322
date_time = datetime.fromtimestamp(timestamp)

print("Date time object:", date_time)

d = date_time.strftime("%m/%d/%Y, %H:%M:%S")
print("Output 2:", d)	

d = date_time.strftime("%d %b, %Y")
print("Output 3:", d)

d = date_time.strftime("%d %B, %Y")
print("Output 4:", d)

d = date_time.strftime("%I%p")
print("Output 5:", d)

0
0
0
0
Mcdoty 160 points

                                    
from datetime import datetime

timestamp = 1528797322
date_time = datetime.fromtimestamp(timestamp)

print("Date time object:", date_time)

d = date_time.strftime("%m/%d/%Y, %H:%M:%S")
print("Output 2:", d)	

d = date_time.strftime("%d %b, %Y")
print("Output 3:", d)

d = date_time.strftime("%d %B, %Y")
print("Output 4:", d)

d = date_time.strftime("%I%p")
print("Output 5:", d)

0
0
0
0
Mcdoty 160 points

                                    
from datetime import datetime

timestamp = 1528797322
date_time = datetime.fromtimestamp(timestamp)

print("Date time object:", date_time)

d = date_time.strftime("%m/%d/%Y, %H:%M:%S")
print("Output 2:", d)	

d = date_time.strftime("%d %b, %Y")
print("Output 3:", d)

d = date_time.strftime("%d %B, %Y")
print("Output 4:", d)

d = date_time.strftime("%I%p")
print("Output 5:", d)

0
0
0
0
Mcdoty 160 points

                                    
from datetime import datetime

timestamp = 1528797322
date_time = datetime.fromtimestamp(timestamp)

print("Date time object:", date_time)

d = date_time.strftime("%m/%d/%Y, %H:%M:%S")
print("Output 2:", d)	

d = date_time.strftime("%d %b, %Y")
print("Output 3:", d)

d = date_time.strftime("%d %B, %Y")
print("Output 4:", d)

d = date_time.strftime("%I%p")
print("Output 5:", d)

0
0
0
0
Mcdoty 160 points

                                    
from datetime import datetime

timestamp = 1528797322
date_time = datetime.fromtimestamp(timestamp)

print("Date time object:", date_time)

d = date_time.strftime("%m/%d/%Y, %H:%M:%S")
print("Output 2:", d)	

d = date_time.strftime("%d %b, %Y")
print("Output 3:", d)

d = date_time.strftime("%d %B, %Y")
print("Output 4:", d)

d = date_time.strftime("%I%p")
print("Output 5:", d)

0
0
0
0
Mcdoty 160 points

                                    
from datetime import datetime

timestamp = 1528797322
date_time = datetime.fromtimestamp(timestamp)

print("Date time object:", date_time)

d = date_time.strftime("%m/%d/%Y, %H:%M:%S")
print("Output 2:", d)	

d = date_time.strftime("%d %b, %Y")
print("Output 3:", d)

d = date_time.strftime("%d %B, %Y")
print("Output 4:", d)

d = date_time.strftime("%I%p")
print("Output 5:", d)

0
0
0
0
Mcdoty 160 points

                                    
from datetime import datetime

timestamp = 1528797322
date_time = datetime.fromtimestamp(timestamp)

print("Date time object:", date_time)

d = date_time.strftime("%m/%d/%Y, %H:%M:%S")
print("Output 2:", d)	

d = date_time.strftime("%d %b, %Y")
print("Output 3:", d)

d = date_time.strftime("%d %B, %Y")
print("Output 4:", d)

d = date_time.strftime("%I%p")
print("Output 5:", d)

0
0
0
0
Mcdoty 160 points

                                    
from datetime import datetime

timestamp = 1528797322
date_time = datetime.fromtimestamp(timestamp)

print("Date time object:", date_time)

d = date_time.strftime("%m/%d/%Y, %H:%M:%S")
print("Output 2:", d)	

d = date_time.strftime("%d %b, %Y")
print("Output 3:", d)

d = date_time.strftime("%d %B, %Y")
print("Output 4:", d)

d = date_time.strftime("%I%p")
print("Output 5:", d)

0
0
0
0
Mcdoty 160 points

                                    
from datetime import datetime

timestamp = 1528797322
date_time = datetime.fromtimestamp(timestamp)

print("Date time object:", date_time)

d = date_time.strftime("%m/%d/%Y, %H:%M:%S")
print("Output 2:", d)	

d = date_time.strftime("%d %b, %Y")
print("Output 3:", d)

d = date_time.strftime("%d %B, %Y")
print("Output 4:", d)

d = date_time.strftime("%I%p")
print("Output 5:", d)

0
0
0
0
Mcdoty 160 points

                                    
from datetime import datetime

timestamp = 1528797322
date_time = datetime.fromtimestamp(timestamp)

print("Date time object:", date_time)

d = date_time.strftime("%m/%d/%Y, %H:%M:%S")
print("Output 2:", d)	

d = date_time.strftime("%d %b, %Y")
print("Output 3:", d)

d = date_time.strftime("%d %B, %Y")
print("Output 4:", d)

d = date_time.strftime("%I%p")
print("Output 5:", d)

0
0
0
0
Mcdoty 160 points

                                    
from datetime import datetime

timestamp = 1528797322
date_time = datetime.fromtimestamp(timestamp)

print("Date time object:", date_time)

d = date_time.strftime("%m/%d/%Y, %H:%M:%S")
print("Output 2:", d)	

d = date_time.strftime("%d %b, %Y")
print("Output 3:", d)

d = date_time.strftime("%d %B, %Y")
print("Output 4:", d)

d = date_time.strftime("%I%p")
print("Output 5:", d)

0
0
0
0
Mcdoty 160 points

                                    
from datetime import datetime

timestamp = 1528797322
date_time = datetime.fromtimestamp(timestamp)

print("Date time object:", date_time)

d = date_time.strftime("%m/%d/%Y, %H:%M:%S")
print("Output 2:", d)	

d = date_time.strftime("%d %b, %Y")
print("Output 3:", d)

d = date_time.strftime("%d %B, %Y")
print("Output 4:", d)

d = date_time.strftime("%I%p")
print("Output 5:", d)

0
0
0
0
Mcdoty 160 points

                                    
from datetime import datetime

timestamp = 1528797322
date_time = datetime.fromtimestamp(timestamp)

print("Date time object:", date_time)

d = date_time.strftime("%m/%d/%Y, %H:%M:%S")
print("Output 2:", d)	

d = date_time.strftime("%d %b, %Y")
print("Output 3:", d)

d = date_time.strftime("%d %B, %Y")
print("Output 4:", d)

d = date_time.strftime("%I%p")
print("Output 5:", d)

0
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
time.strftime('%Y-%m-%d') strftime date and time format strf datetime strftime time datetime strft datetime.now.strftime time.strftime format strftime import time Time.now.strftime datetime.strftime how to use time.strftime("%d/%m/%Y") t=time.strftime('%I:%M:%S %p',time.localtime()) python datetime.date.strftime strf time datatime datetime strftime format datetime strf what is time.strftime("%I:%M:%S" time.strftime("%I:%M:%S" datetime date strftime strftime .strftime( strftime("%s" d.strftime strftime with date and time datetime.strf how to use strftime datetime.time.strftime time.strftime("%-I:%M %p") date strftime datetime .strftime dateimte strftime time.time() strftime what is %I .strftime strftime( what is strftime .date().strftime datetime strftime function time strftime python strftime datetime "strftime" now.strftime datetime.strftime python use of strftime in python strftime() datetime.date strftime time.strftime( python datetime.strftime time.strftime("%Y-%m-%d") time.strftime() python how to use datetime strftime datetime.strftime() date time strftime python time .format string date.strftime time.deltatime time .struct time compare time.struct_time to strptime .strftime python datetime.datetime obj to hours minute now().strftime str from time python strfromtime format time.strftime(%m) strftime formats strftime vs strptime python s_time.strftime MATPLOTlib STRFTIME strftime('%A')) strftime in python\ datetime object convert to string datetime.strftime datetime.time.strptime datetime.time datetime strftime strftime python3 strptime strftime get datetime python to string python % string format now strftime django what is strftime in python strftime converter function python %H %M %p python strftime meaning time.strftime() time.strftime("%p") .strftime time python strftime python time strftime python how to use strftime time strftime python time time strftime convert step to strf strftime python strftime format :2 convert python time to real time time in python for number of seconds python %time time function python python time() import time python Time.time tm_wday python time.localtime() python format python time.time strftime localtime timegmtime() strftime python datetime django strftime python time mktime utc time in seconds python how does the python time libary work time.time in seconds python time.strftime('%Y') python date time string format os.ctiime to time.time time with python how to check for time using time.time() python get time int py time.time() python time adjust time strftime py strftime("%Y.%m") convert time function python how to simulate epoch python using strftime python import gmtime strftime python time not importing datetime.datetime.strftime time string in python time . time python time.strptime strftime('%Y-%m-30) now strftime strftime for year in python is there a time module in python python time now seconds python difference struct_time python time.localtime() python set time.time precision times times python python string time format time.time() in python strfTime (Time) time.time() time format string python time.gmtime strftime month year day using strftime in python secons python python timemodule week convert garmin time to standard time python What does the time () function return in python? python time.time return %time output python start and end time.time() python datetime to string python with format what is %%time in python datatime string format python time = time python in sexornds TIME.strftime python time.time get seconds time.mktime time.time in python datetime.localtime function in python module python time time is seconds for clock python t.time() python python when time is time for 24 hours python year and time format in python time of python time.time clock python time.strftime in python python time.time form clock python python localtime is not defined 2/5/2020 8:00:00 AM to epoch python seconds since 1970 python date time string python time library for python python modulo get time after 1 hour get utc time from epoch python time time() python python readtime time conversation python python time.time strftime python time function return value python time Mon tue python datetime strftime format string format of date time on pythn time.strftime python time python python time conversion python time module timer strftime python example python strftime independent sleep python python date to string python string from time python time format time python function time.time() returns in python python time.gmtime implementation python time how to specify time using time module in python how to use local time in python time conversion python utc time 00:30 python convert time.time() to string python TIME STRING FROM TIME.TIME %%time in python python datetime string format python module time datetime.strftime example time.strftime python 3 python time is forenoon python current time to strin format python times python time without importing any libraries time library in python sleep time value in pythong python datetime.date strftime time module in python datetime format strings in python 12 hour string strftime example python datetime strftime time.strftime example python time standard format python strf time python datetime to string python time.time() python time from string format print time as string python date and time format from string python python time.clock() time.localtime python time python + time python format time datetime string python format for python defined times time in python exemple strptimpe python exemple strftimpe python python time function time.clock python python dateformat string python time.time return type time library in python time.localtime python example local time python python clock datetime python strftime times in python time clock python python import time date time string format python python datetime string python starttime time.time() %%time python convert time to string in python time done in python datetime python to string python datetime datetime format string python format datetime to string python datetime strfime time.time python time.time() python in seconds datetime formats python python time.time python import time python time.strftime time() python how does the time library work python time.time() python what is time.time() in python time.localtime time library python strftime python python time time time module return value python time module return value time module python
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source