datetime的常用

  

# 1、datetime 一些常用的
import datetime
now = datetime.datetime.now()            # 当前时间 2018-10-22 17:34:10.665324
print(now)
today = datetime.date.today()            # 今天的年月日  2018-10-22
print(today)
# formatTime = now.strftime("%Y-%m-%d")        # 按格式输出  年月日
formatTime = now.strftime("%Y-%m-%d %H:%M:%S") # 年月日 时分秒
print(formatTime)
# 时间戳
chuo = datetime.timedelta(seconds=20)
chuo1 = datetime.timedelta(seconds=20)-datetime.timedelta(seconds=10)
chuo2 = now - datetime.timedelta(seconds=20)
print(chuo)   # 0:00:20
print(chuo1)  # 0:00:10
print(chuo2)  # now=2018-10-22 18:32:26.951076  2018-10-22 18:32:06.951076
# 2、在orm中,时间可以用lt和gt比较大小
# last_consult_date__lt = chuo
# last_consult_date__gt = chuo

 

posted @ 2018-10-22 18:41  fangsheng420  阅读(120)  评论(0编辑  收藏  举报