示例代码:
import time
data: float = time.time()
'''1647007085.3922167'''
data: time.struct_time = time.localtime()
'''time.struct_time(tm_year=2022, tm_mon=3, tm_mday=11, tm_hour=21, tm_min=59, tm_sec=23, tm_wday=4, tm_yday=70, tm_isdst=0)'''
data: time.struct_time = time.localtime(time.time())
'''time.struct_time(tm_year=2022, tm_mon=3, tm_mday=11, tm_hour=22, tm_min=1, tm_sec=36, tm_wday=4, tm_yday=70, tm_isdst=0)'''
data: str = time.strftime("%Y-%m-%d %H:%M:%S %z", time.localtime(time.time()))
"2022-03-11 22:05:46 +0800"
data: time.struct_time = time.strptime("2022-03-11 22:05:46 +0800", "%Y-%m-%d %H:%M:%S %z")
'''time.struct_time(tm_year=2022, tm_mon=3, tm_mday=11, tm_hour=22, tm_min=1, tm_sec=36, tm_wday=4, tm_yday=70, tm_isdst=0)'''
data = time.mktime(time.localtime(time.time()))
"1647008454.0"
有这么几个细节:
- Python的时区是东八区,arrow这个工具不是。
- Python没有毫秒级的展示(似乎),你看转化为structime就没有毫秒了
- 在float里面是记录了距离1970以后的秒数,1=1S
- Python的时间工具类有两个特点:原生,不需要依赖库。比较适合大型项目