import time
print (time.strftime('%Y-%m-%d %H:%M:%S'))
上面这行其实就是下面这行的简写,因为strftime方法第二个参数默认就是time.localtime
print (time.strftime('%Y-%m-%d %H:%M:%S',time.localtime()))
附上strftime的帮助
>>> help(time.strftime)
Help on built-in function strftime in module time:
strftime(...)
strftime(format[, tuple]) -> string
Convert a time tuple to a string according to a format specification.
See the library reference manual for formatting codes. When the time tuple
is not present, current time as returned by localtime() is used.
Commonly used format codes:
%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.
Other codes may be available on your platform. See documentation for
the C library strftime function.
阅读(697) | 评论(0) | 转发(0) |