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


  • 相关阅读:
    java.sql.SQLException: 不支持的字符集 (在类路径中添加 orai18n.jar): ZHS16GBK
    STS工具各版本下载网址
    SpringBoot访问不了JSP但却能进入后台
    springboot o.a.tomcat.util.scan.StandardJarScanner : Failed to scan [file:/D:/apache-maven-3.0.5[系统找不到指定路径]
    STS工具:mybayis连接oracle数据库
    springBoot怎样访问静态资源?+静态资源简介
    springboot注解
    8.12-14 df 、mkswap、swapon、swapoff、sync
    8.5-7 mkfs、dumpe2fs、resize2fs
    8.2-3 partprobe、tune2fs
  • 原文地址:https://www.cnblogs.com/111testing/p/10424933.html
Copyright © 2011-2022 走看看