Python基础-时间函数使用

import  time

#返回当前时间的时间戳(1970纪元后经过的浮点秒数)。
print(time.time())
#用以浮点数计算的秒数返回当前的CPU时间。用来衡量不同程序的耗时,比time.time()更有用
print(time.clock())
#接收时间戳(1970纪元后经过的浮点秒数)并返回格林威治天文时间下的时间元组t。注:t.tm_isdst始终为0
print(time.gmtime(1614005152.7187028))

#接收时间戳(1970纪元后经过的浮点秒数)并返回当地时间下的时间元组t(t.tm_isdst可取0或1,取决于当地当时是不是夏令时)
print(time.localtime())

#2021-02-22-22-53-39-+0800-Mon-Monday-Feb-February-Mon Feb 22 22:53:39 2021-10-PM
print(time.strftime("%Y-%m-%d-%H-%M-%S-%z-%a-%A-%b-%B-%c-%I-%p",time.localtime()))
'''
%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.#
'''