Python Version (使用版本):
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47)
[MSC v.1914 32 bit (Intel)] on win32
Time : 2021年6月8日22:24:58 By: MemoryEr 公众号: 源来科技工作室
一 简单用法,打印查看并对比使用
import datetime
#导入库
GetNow = datetime.datetime.now()
#打印当前时间
print("当前时间 :",GetNow)
GetYear = datetime.datetime.now().year
GetMonth = datetime.datetime.now().month
GetDay = datetime.datetime.now().day
#打印对应值: 年-月-日
print("年-月-日 :",GetYear,GetMonth,GetDay)
GetHour = datetime.datetime.now().hour
GetMinute = datetime.datetime.now().minute
GetSecond = datetime.datetime.now().second
#打印对应值: 时-分-秒
print("时-分-秒 :",GetHour,GetMinute,GetSecond)
print(type(GetHour))
#获取返回的类型是: 整数型,对比参数时,需要对应转化.
if GetHour >=23 :
print("Game Over !")
else:
print("Are you ok ?")