web123456

python learning strptime and strftime methods

strftime
describe
The Python time strftime() function receives a tuple of time and returns the local time represented as a readable string, the format is determined by the parameter format.
grammar
strftime() method syntax:
(format[, t])
parameter
format -- Format string.
t -- The optional parameter t is a struct_time object.
Return value
Returns the local time represented in a readable string.

strptime
describe
The Python time strptime() function parses a time string into a time tuple based on the specified format.
grammar
strptime() method syntax:
(string[, format])
parameter
string -- a time string.
format -- Format string
Return value
Returns the struct_time object.
illustrate
Time and date formatting symbols in python:
%y Double digit year representation (00-99)
%Y Four-digit year representation (000-9999)
%m Month (01-12)
%d One day in the month (0-31)
%H 24-hour hours (0-23)
%I 12-hour hours (01-12)
%M Minutes (00=59)
%S seconds (00-59)
%a Local simplified week name
%A Local full week name
%b Locally simplified month name
%B Local full month name
%c Local corresponding date and time representation
%j One day in the year (001-366)
%p local .or. equivalence
%U The number of weeks of the year (00-53) Sunday is the beginning of the week
%w Week (0-6), Sunday is the beginning of the week
%W The number of weeks of the year (00-53) Monday is the beginning of the week
%x local corresponding date
%X local corresponding time representation
%Z The name of the current time zone
%% % % number itself