zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    webservice4
    webservice2
    webservice3
    webservice
    java 堆栈分析4
    java 堆栈分析3
    java 堆栈分析2
    java 堆栈分析
    数据库的Timeout
    node.js小结 2
  • 原文地址:https://www.cnblogs.com/fangsheng/p/9831904.html
Copyright © 2011-2022 走看看