zoukankan      html  css  js  c++  java
  • python实现当前时间后推三个月

    由当前时间向后推3个月

    def index_time():
        end_time = time.time()
        end_date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(end_time))
        date_list_1 = end_date.split('-')
        date_list_2 = date_list_1[2].split(' ')
        date_d = date_list_2[0]
        date_Y = date_list_1[0]
        date_m = date_list_1[1]
        print('当前的年份', date_Y)
        print('当前的月份', date_m)
        print('当前日期',date_d)
        if int(date_Y) % 4 == 0:
            print('润年2月29天')
            if date_m in ['1', '2', '6', '8', '9', '10', '11']:
                if date_d in ['31']:
                    start_time = end_time - 86400 * 93
                    start_date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(start_time))
                else:
                    start_time = end_time - 86400 * 92
                    start_date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(start_time))
            elif date_m in ['3', '4', '7', '12']:
                if date_d in ['31']:
                    start_time = end_time - 86400 * 92
                    start_date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(start_time))
                else:
                    start_time = end_time - 86400 * 91
                    start_date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(start_time))
            else:
                if date_d in ['30']:
                    start_time = end_time - 86400 * 91
                    start_date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(start_time))
                elif date_d in ['31']:
                    start_time = end_time - 86400 * 92
                    start_date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(start_time))
                else:
                    start_time = end_time - 86400 * 90
                    start_date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(start_time))
        else:
            print('非润年2月28天')
            if date_m in ['1', '2', '6', '8', '9', '10', '11']:
                if date_d in ['31']:
                    start_time = end_time - 86400 * 93
                    start_date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(start_time))
                else:
                    start_time = end_time - 86400 * 92
                    start_date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(start_time))
            elif date_m in ['7', '12']:
                if date_d in ['31']:
                    start_time = end_time - 86400 * 92
                    start_date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(start_time))
                else:
                    start_time = end_time - 86400 * 91
                    start_date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(start_time))
            elif date_m in ['3', '4']:
                if date_d in ['31']:
                    start_time = end_time - 86400 * 91
                    start_date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(start_time))
                else:
                    start_time = end_time - 86400 * 90
                    start_date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(start_time))
            else:
                if date_d in ['29']:
                    start_time = end_time - 86400 * 90
                    start_date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(start_time))
                elif date_d in ['30']:
                    start_time = end_time - 86400 * 91
                    start_date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(start_time))
                elif date_d in ['31']:
                    start_time = end_time - 86400 * 92
                    start_date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(start_time))
                else:
                    start_time = end_time - 86400 * 89
                    start_date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(start_time))
        print('开始时间', start_date)
        print('开始时间', end_date)
        return end_date, start_date
    
  • 相关阅读:
    分页查询SQL语句
    屏蔽Ctrl+C
    RichtextBox 控件小节
    必须掌握的八个CMD命令
    [唠叨两句]一个关于OpenFileDialog 影响 相对路径的问题
    反序列化出现异常:SerializationException 在分析完成之前就遇到流结尾
    Static块(静态代码块)
    Java ServletContext 详解
    tomcat中conf\Catalina\localhost目录下的J2EE项目METAINF配置文件
    关于【apache tomcat 5.5.15/conf /Catalina/localhost配置虚拟目录】时的一些问题。(配置web项目的方式不止一种,虚拟目录就是一个)
  • 原文地址:https://www.cnblogs.com/mqhpy/p/14188452.html
Copyright © 2011-2022 走看看