在Python中,通常有这几种方式来表示时间:1)时间戳 2)格式化的时间字符串 3)元组(struct_time)共九个元素。

  1. 时间戳(timestamp):
    通常来说,时间戳表示的是从1970年1月1日00:00:00开始按秒计算的偏移量。

  2. 时间字符串
    time模块

  3. 元组(struct_time)
    元组方式共有9个元素。
    time模块

  4. 转化关系
    time模块

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

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

相关文章: