For time formatting like 'wed, 11 Apr 2012 09:37:05 + 123', the following solutions are provided:
>>> Date = 'wed, 11 Apr 2012 09:37:05 + 0800'
>>> Dd = datetime. datetime. strptime (date, '% A, % d % B % Y % H: % m: % S % Z ')
>>> Dd. strftime ('% Y-% m-% d % H: % m: % s ')
The function for formatting the date and time in python is datetime. datetime. strftime (); Convert from string to date type function: datetime. datetime. strptime (), two functions are involved in the format string of the date and time, as shown below:
% A abbreviated weekday name % A full weekday name % B abbreviated month name % B full month name % C Date And Time Representation appropriate For Locale % D day of month as decimal number (01-31 ) % H hour In 24-hour format (00-23 ) % I hour In 12-hour format (01-12 ) % J day of year as decimal number (001-366) ) % M month as decimal number (01-12 ) % M minute as decimal number (00-59 ) % P current locale ' S a. m./P. M. Indicator for 12-hour clock % S second as decimal number (00-59 ) % U week of year as decimal number, with Sunday as first day of week (00-51 ) % W weekday as decimal number (0-6; Sunday Is 0) % W week of year as decimal number, with Monday as first day of week (00-51 ) % X date Representation For Current locale % X Time Representation For Current locale % Y year without Century, as decimal number (00-99 ) % Y year with Century, as decimal number % Z, % Z time-zone name Or Abbreviation; no characters If Time Zone Is Unknown % Percent sign