dt = date(2018,8,6)
print(dt , type(dt))
# 2018-08-06 <class 'datetime.date'>
t = time(20,20,20)
print(t)
# 20:20:20
dtt = datetime(2018,11,16,20,20,20,1000)
print(dtt)
#2018-01-01 20:20:20.001000
****# ps = timedelta(hours=12) #间隔多少时间
print(ps, type(ps))
# 12:00:00 <class 'datetime.timedelta'>
****# print(dtt + ps) #时间+ 时间间隔 得到 12小时后的时间.
# 2018-11-17 08:20:20.001000
*** now = datetime.now()
print(now)
utc = datetime.utcnow()
print(utc)
utcnow() 得到格林威治时间.
**** #strptime解析时间 把字符串 转成日期 (format 格式对应前面的, 变成 yyyy-mm-dd hh: mm :ss)
strp = datetime.strptime('2018-8-6 21:15:00','%Y-%m-%d %H:%M:%S')
strp2 = datetime.strptime('Sep-6-18 21:15:00','%b-%d-%y %H:%M:%S')
print(strp,' ', strp2)
strftime 格式化 时间.strftime
***** strf = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
print(strf)
t1 = datetime.fromtimestamp(0) #从1970-01-01 开始. 到某个时间点的 秒数.
*** t2 = datetime.fromtimestamp(1111111) #把时间戳 转换成日期
tdlt = t2 - t1
print(t1 ,t2 ,'过去了',tdlt,type(tdlt))
***** print(t2.timestamp() ) #把 日期 转换成 时间戳
print(datetime.now().timestamp())
print(now.weekday()) #取值范围 0-6
print(now.isoweekday()) #取值范围 1-7
网友评论