zoukankan      html  css  js  c++  java
  • python获取当前,昨天,明天时间

    import datetime
    nowTime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')#现在
    pastTimeMinutes = (datetime.datetime.now()+datetime.timedelta(minutes=5)).strftime('%Y-%m-%d %H:%M:%S')#5分钟后
    pastTime = (datetime.datetime.now()-datetime.timedelta(hours=1)).strftime('%Y-%m-%d %H:%M:%S')#一小时前
    afterTomorrowTime = (datetime.datetime.now()+datetime.timedelta(days=2)).strftime('%Y-%m-%d %H:%M:%S')#后天
    yesterday = (datetime.datetime.now()-datetime.timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S')#昨天
    tomorrowTime = (datetime.datetime.now()+datetime.timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S')#明天
    # print('
    ',nowTime,'
    ',pastTimeMinutes,'
    ',pastTime,'
    ',afterTomorrowTime,'
    ',tomorrowTime)
    print("现在:    "+nowTime)
    print("5分钟后: "+pastTimeMinutes)
    print("一小时前: "+pastTime)
    print("后天:    "+afterTomorrowTime)
    print("昨天:    "+yesterday)
    print("明天:    "+tomorrowTime)
    import datetime
    nowTime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')#现在
    pastTimeMinutes = (datetime.datetime.now()+datetime.timedelta(minutes=5)).strftime('%Y-%m-%d %H:%M:%S')#5分钟后
    pastTime = (datetime.datetime.now()-datetime.timedelta(hours=1)).strftime('%Y-%m-%d %H:%M:%S')#一小时前
    afterTomorrowTime = (datetime.datetime.now()+datetime.timedelta(days=2)).strftime('%Y-%m-%d %H:%M:%S')#后天
    yesterday = (datetime.datetime.now()-datetime.timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S')#昨天
    tomorrowTime = (datetime.datetime.now()+datetime.timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S')#明天
    # print('
    ',nowTime,'
    ',pastTimeMinutes,'
    ',pastTime,'
    ',afterTomorrowTime,'
    ',tomorrowTime)
    print("现在:    "+nowTime)
    print("5分钟后: "+pastTimeMinutes)
    print("一小时前: "+pastTime)
    print("后天:    "+afterTomorrowTime)
    print("昨天:    "+yesterday)
    print("明天:    "+tomorrowTime)

    总结:

    +datetime.timedelta(minutes=5)     加5分钟也就是5分钟之后的时间
    -datetime.timedelta(days=1)        减1天时间也就是1天前的时间  


  • 相关阅读:
    HDU 5852 Intersection is not allowed!(LGV定理行列式求组合数)题解
    FJNU2018低程F jq解救fuls (贪心乱搞)题解
    Gym 101775J Straight Master(差分数组)题解
    FJUT3591 侦测到在途的聚变打击(最小不可相交路径覆盖)题解
    HDU 6406 Taotao Picks Apples & FJUT3592 做完其他题后才能做的题(线段树)题解
    vijos 1907 飞扬的小鸟
    vijos 1779 国王游戏
    BZOJ 3439 Kpm的MC密码
    BZOJ 3163 Eden的新背包问题
    codevs 5429 完全背包
  • 原文地址:https://www.cnblogs.com/111testing/p/10424933.html
Copyright © 2011-2022 走看看