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天前的时间  


  • 相关阅读:
    ZooKeeper系列
    CST和GMT时间的区别
    ZooKeeper系列之二:Zookeeper常用命令
    分布式服务框架 Zookeeper -- 管理分布式环境中的数据
    ZooKeeper资料
    分布式选举算法
    初识ZooKeeper与集群搭建实例
    原子广播
    Apache ZooKeeper
    工作流引擎
  • 原文地址:https://www.cnblogs.com/111testing/p/10424933.html
Copyright © 2011-2022 走看看