美文网首页老男孩Python全栈
第2模块第2章9常用模块学习—time模块详解

第2模块第2章9常用模块学习—time模块详解

作者: 飞鸟在笼 | 来源:发表于2019-03-14 11:18 被阅读18次

    time.time()时间戳

    time.localtime([secs]):将一个时间戳转换为当前时区的struct_time。secs参数未提供,则以当前时间为准。

    time.gmtime([secs]):和localtime()方法类似,gmtime()方法是将一个时间戳转换为UTC时区(0时区)的struct_time。

    英国时间,比北京时间晚8小时

    time.time():返回当前时间的时间戳。

    time.mktime(t):将一个struct_time转化为时间戳。

    time.sleep(secs):线程推迟指定的时间运行。单位为秒。

    time.asctime([t]):把一个表示时间的元组或者struct_time表示为这种形式:'Sun Oct 1 12:04:38 2017'。如果没有参数,将会将time.localtime()作为参数传入。

    time.ctime([secs]):把一个时间戳(按秒计算的浮点数)转化为time.asctime()的形式。如果参数未给或者为None的时候,将会默认time.time()为参数。它的作用相当于time.asctime(time.localtime(secs))。

    time.strftime(format[, t]):把一个代表时间的元组或者struct_time(如由time.localtime()和time.gmtime()返回)转化为格式化的时间字符串。如果t未指定,将传入time.localtime()。

    举例:time.strftime("%Y-%m-%d %X", time.localtime()) #输出'2017-10-01 12:14:23'

    time.strptime(string[, format]):把一个格式化时间字符串转化为struct_time。实际上它和strftime()是逆操作。

    举例:time.strptime('2017-10-3 17:54',"%Y-%m-%d %H:%M") #输出 time.struct_time(tm_year=2017, tm_mon=10, tm_mday=3, tm_hour=17, tm_min=54, tm_sec=0, tm_wday=1, tm_yday=276, tm_isdst=-1)

    相关文章

      网友评论

        本文标题:第2模块第2章9常用模块学习—time模块详解

        本文链接:https://www.haomeiwen.com/subject/lixqmqtx.html