time库是python处理时间数据的标准库

time库有3种时间表现方式:

python标准库之time库

time库主要提供3类属性:

1、time库时间获取属性:

python标准库之time库

python标准库之time库

gmtime与localtimex,ctime与 asctime的比较

不同的是:

gmtime 返回的是 电脑时间的格林威治时间,也就是0时区的时间, localtime 返回的是 电脑时间

ctime接收浮点数形式的时间格式,asctiem接收元组时间格式

相同的是:

两者返回的时间格式都是元组形式

两者返回的都是字符串形式的时间格式

 time库格式化属性:

time.strftiem(formt, tuple)  #其作用是将struc_time转换为模板格式的字符串时间,易于阅读。

python标准库之time库

 

format 表示模板格式如 "%Y-%m-%d %H:%M:%S" ,tuple 表示 struct_time。

time.strptiem(str, format)  # 将字符串形式的时间转换为stuct_time

python标准库之time库

 python标准库之time库

3、程序计时类属性

python标准库之time库

推荐使用per_counter、process_time精度较高:

两者区别:

perf_counter: 含起始和终止的所有时间,包含sleep时间

process_time: 不含进程sleep时间。

python标准库之time库

 

相关文章:

  • 2021-12-05
  • 2021-11-29
  • 2022-12-23
  • 2021-09-12
  • 2022-02-22
猜你喜欢
  • 2021-10-08
  • 2022-12-23
  • 2021-09-03
  • 2022-02-20
  • 2022-02-13
  • 2021-10-12
相关资源
相似解决方案