• 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
    
  • 相关阅读:
    Mysql数据库改名
    查看数据库大小或者表大小
    Bootstarp 水平垂直居中
    Java Collection.sort 排序升序, 降序问题
    Mysql 函数, 存储过程, 任务调度
    Mysql 日期类型 date、datetime、timestamp.
    Mysql 获取当天,昨天,本周,本月,上周,上月的起始时间
    Mysql 事件event_scheduler是OFF
    Java 文件读取
    Spring cron 定时调度配置
  • 原文地址:https://www.cnblogs.com/mqhpy/p/14188452.html
Copyright © 2020-2023  润新知