stftime()

strftime() : Returns date string by using formatted input .

Today's date details using strftime()

from datetime import date
dt=date.today().strftime('%Y-%m-%d')
print(dt)
Output
2019-09-17
Date with time
from datetime import datetime
dt=datetime.now().strftime('%c')
print(dt)
Output
Tue Sep 17 10:51:02 2019

Using date object

import datetime
# Year, Month, date, Hour, Minute , Second, mircosecond 
dt=datetime.datetime(2019,12,31,23,59,59,345234)
print(dt.strftime('%Y-%m-%d  %H:%M:%S'))
Output
2019-12-31  23:59:59
Add Microsecond
print(dt.strftime('%Y-%m-%d  %H:%M:%S - %f'))
output
2019-12-31  23:59:59 - 345234
List of format codes used with strftime()
%aWeekday (short)
Sun, Mon ...
%AWeekday (long )
Sunday, Monday ...
%wWeekday in decimal
0,1 ... (Here Sun=0, Mon=1) ...
%dDay of the month with zero padded
01,02,03 .... 11,12....
%bMonth ( short)
Jan, Feb ...
%BMonth ( Long )
January , February ...
%mMonth ( number )
01,02 ... 11,12
%yYear ( short )
01,02 ... 19,20 ...
%YYear ( Long )
1998,2013 ...
%HHour ( 24 hour )
01,02.. 22,23
%IHour (12 Hour )
01,02 ..12
%pAM or PM
or am mp ( de_DE).
%MMinutes
01,02.. 59
%SSeconds
01,02 .. 59
%fMicrosecond
000001,000002 .. 999999
%zUTC offset in terms of HHMM ( + or - )
0000,-0130,0530..
%ZTime zone name
UTC, CST , EST
%jday of the year ( zero padded )
004,121 .. 365
%UWeekday of the Year ( zero padded), Sunday as first day of the week
02,04 .. 53
%WWeekday of the Year ( zero padded), Monday as first day of the week
02,04 .. 53
%cLocale’s appropriate date and time
Tue Dec 31 23:59:59 2019
%xLocale’s appropriate date
12/31/19
%XLocale’s appropriate Time
23:59:59
All Date Objects
Your Rating




Post your comments , suggestion , error , requirements etc here




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2019 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer