• python计算当前时间的前(后)一分钟,前(后)一小时,前(后)一天


    #计算当前时间
    
    import datetime
    datetime.datetime.now()
    # 2019-06-30 10:51:14.089271
    # 格式化时间
    datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    # 2019-06-30 10:52:05
    
    #多加(减)一天
    
    (datetime.datetime.now()+datetime.timedelta(days=1)).strftime("%Y-%m-%
    d %H:%M:%S")
    # 2019-07-01 10:54:44
    (datetime.datetime.now()-datetime.timedelta(days=1)).strftime("%Y-%m-%
    d %H:%M:%S")
    # 2019-06-29 10:55:44
    
    
    #多加(减)一小时
    
    (datetime.datetime.now()+datetime.timedelta(hours=1)).strftime("%Y-%m-%d %H:%M:%S")
    # 2019-06-30 11:56:46
    (datetime.datetime.now()-datetime.timedelta(hours=1)).strftime("%Y-%m-%d %H:%M:%S")
    # 2019-06-30 09:58:02
    
    
    多加(减)一分钟
    
    (datetime.datetime.now()+datetime.timedelta(minutes=1)).strftime("%Y-%m-%d %H:%M:%S")
    (datetime.datetime.now()-datetime.timedelta(minutes=1)).strftime("%Y-%m-%d %H:%M:%S")
  • 相关阅读:
    zoj1589Professor John
    zoj1082Stockbroker Grapevine
    zoj1311Network
    zoj1060Sorting It All Out
    zoj1119SPF
    zju1085Alien Security
    zoj 2474Benny's Compiler
    zoj1068P,MTHBGWB
    what's next?
    ski for the first time~
  • 原文地址:https://www.cnblogs.com/lgj8/p/13500619.html
Copyright © 2020-2023  润新知