Python程序能够用很多方式处理日期和时间,转换时间格式是一个常见的功能。
1、time模块
提供了处理时间和表示之间转换的功能
①获取当前时间戳
时间戳
(1)概念:从0时区的1970年1月1日0时0分0秒,到所给定日期时间的秒数。是一个浮点数
(2)获取方式:import time
time.time()
②获取时间元组
③获取格式化的时间:将时间戳(秒)->格式化时间
④格式化日期字符串
⑤休眠n秒
2、calendar模块
提供与日历相关的功能,比如:为给定的月份或者年份打印文本日历的功能(仅作了解)
3、datetime模块