In [16]: time.strftime('%Y-%m-%d %H:%M:%S') Out[16]: '2023-02-25 17:16:20'
用到的格式有如下
%Y Year with century as a decimal number. %m Month as a decimal number [01,12]. %d Day of the month as a decimal number [01,31]. %H Hour (24-hour clock) as a decimal number [00,23]. %M Minute as a decimal number [00,59]. %S Second as a decimal number [00,61]. %z Time zone offset from UTC. %a Locale’s abbreviated weekday name. %A Locale’s full weekday name. %b Locale’s abbreviated month name. %B Locale’s full month name. %c Locale’s appropriate date and time representation. %I Hour (12-hour clock) as a decimal number [01,12]. %p Locale’s equivalent of either AM or PM.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
In [18]: time.strptime? Docstring: strptime(string, format) -> struct_time
Parse a string to a time tuple according to a format specification. See the library reference manual for formatting codes (same as strftime()).