datetime
-
dateime :对象,Python一切皆对象
-
datetime.now() :获取当前时间
-
datetime(2019,7,25,15,20,00) ——————2019-7-2515:20:00 获取的是一个对象
-
用处:记录日志时使用,计算时间
-
# 将当前时间转化成时间戳 # t = datetime.now() # print(t.timestamp()) # 将时间戳转化成当前时间 # import time # print(datetime.fromtimestamp(15000000000)) # 将字符串转成对象 # print(type(datetime.strptime("2019-10-10 22:23:24","%Y-%m-%d %H:%M:%S"))) # 将对象转成字符串 # print(str(datetime.now())) # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S")) # datetime加减 # print(datetime.now() + timedelta(hours=30 * 24 * 12)) # print(datetime.now() - timedelta(hours=30 * 24 * 12))