Day_12_Am_Time_Module
# 时间戳: 指定时间距离1970年1月1日0点的总秒数
# UTC: 国际标准时间
# time模块
import time
print(time.time()) # 当前时间时间戳timestamp
# => 1596508627.7581053
# 睡眠0.2秒, 会阻塞程序
time.sleep(0.2)
# datetime模块
import datetime
# 创建日期对象
d = datetime.datetime.now()
d = datetime.datetime(year=2030, month=1, day=1)
# 日期对象的属性和方法
# print(d)
print(d.year, d.month, d.day) # 日期:年月日
print(d.hour, d.minute, d.second) # 时分秒
print(d.date(), d.time())
print(d.strftime('%y{}%m{}%d{}').format('年', '月', '日'))
# => 20年08月04日
print(d.timestamp()) # 时间戳
# 时间戳 => 日期对象:了解
# print(datetime.datetime.fromtimestamp(2596509826))
# 时间差
d2 = datetime.timedelta(days=7, hours = 10)
print(d + d2) # 7天后十小时后的日期
print(d - d2) # 7天后十小时前的日期