python中的time模块

python3时间模块【官方参数解释】:

python有两个标准的时间表现形式:
1.自从【the Epoch, in UTC (a.k.a. GMT)】【1970 1 1 08:00:00 至现在时刻】的时间秒数:整型或者浮点型
2.包含9个整型的元组去表现本地时间:
The tuple items are:
  year (including century, e.g. 1998)
  month (1-12)
  day (1-31)
  hours (0-23)
  minutes (0-59)
  seconds (0-59)
  weekday (0-6, Monday is 0)
  Julian day (day in the year, 1-366)
  DST (Daylight Savings Time) flag (-1, 0 or 1)
If the DST flag is 0, the time is given in the regular time zone;
if it is 1, the time is given in the DST time zone;
if it is -1, mktime() should guess based on the date and time.

Variables:
timezone -- difference in seconds between UTC and local standard time
altzone -- difference in  seconds between UTC and local DST time
daylight -- whether local time should reflect DST
tzname -- tuple of (standard time zone name, DST time zone name)

Functions:
time() -- return current time in seconds since the Epoch as a float
clock() -- return CPU time since process start as a float
sleep() -- delay for a number of seconds given as a float
gmtime() -- convert seconds since Epoch to UTC tuple
localtime() -- convert seconds since Epoch to local time tuple
asctime() -- convert time tuple to string
ctime() -- convert time in seconds to string
mktime() -- convert local time tuple to seconds since Epoch
strftime() -- convert time tuple to string according to format specification
strptime() -- parse string to time tuple according to format specification
tzset() -- change the local timezone

time.struct_time时间元组参数【struct_time是一个类】:
(年[xx],月[1-12],日[1-31],时[0-23],分[0-59],秒[0-59],星期[0-6],天[1-366],是否夏令[1-夏令、0-非夏、-1[默认未知]])

时间format格式参数:
%y:两位年份【0-99】
%Y:四位年份【2019】
%m:月份【01-12】
%d:天【0-31】
%H:时【0-23】
%I:时【01-12】
%M:分【00-59】
%S:秒【00-59】
%a:星期简写【Mon--->Monday】
%A:星期全称【Monday】
%b:月份简称【Jun--->June】
%B:月份简称【June】
%c:本地适当的日期和时间代表
%p:本地等价与AM或者PM
%z:来自UTC的时间空间

函数分类:
1.所有秒数:
形如:1559034874.5289233
seconds = 【 time.time()、time.mktime(tuple)、calendar.timegm(tuple)】
2.返回时间【一个类】元组:
形如:time.struct_time(tm_year=2019, tm_mon=5, tm_mday=28, tm_hour=16, tm_min=59, tm_sec=55, tm_wday=1, tm_yday=148, tm_isdst=-1)
tuple = 【 time.localtime(seconds)、time.gmtime(seconds)、time.strptime(string,format)】
3.返回格式化字符串:
形如:Tue May 28 16:59:55 2019 、2019-05-28 17:14:34
time.ctime(seconds)、time.asctime(tuple)、time.strftime(format,tuple)
4.CPU时间:
形如:0.3223298026283661
flocat_seconds = time.clock()
5.其它时间:
形如:浮点型
time.sleep(flocat_seconds)

为什么返回的是一个带元组名的元组?为什么返回的时间元组名是struct_time这个类名,参数应该自动获取并返回的?。目前不懂

time()计算秒数:

def time(): # real signature unknown; restored from __doc__

    time() -> floating point number    #无入参,返回浮点数
    '''
    Return the current time in seconds since the Epoch.
    Fractions of a second may be present if the system clock provides them.
    '''
    return 0.0   #表示浮点数,不是0.0
import time
time_total_seconds = time.time()  # 到现在时刻的所有秒数
print("time()返回结果类型:%s" % (type(time_total_seconds)))  # 类型:浮点型<class 'float'>
print("[1970 1 1 08:00:00]到现在时刻历经%s秒" % time_total_seconds)

 

D:\mypy\venv\Scripts\python.exe D:/mypy/tmp.py
time()返回结果类型:<class 'float'>
[1970 1 1 08:00:00]到现在时刻历经1
  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值