时间判断--自定义函数(1)

时间判断--XSY

import time
from datetime import datetime

def DateJudge(s_time):
    #输入日期
    # s_time = 1381419600

    # 转为时间数组
    timeArray = time.strptime(s_time, "%m%d%Y")
    print(timeArray)

    otherStyleTime = time.strftime( "%m%d%Y", timeArray)
    print('目标时间',otherStyleTime)
    # 判断月份
    if timeArray.tm_mon == 1:
        up_time = f'{timeArray.tm_year}-{timeArray.tm_mon}-01'
        week=datetime.strptime(up_time,  "%m%d%Y").weekday()
        print('1月星期', week)
        # 星期判断
        if week > 4 :
            print("4*7= ",4*7)
            return 28
        elif week < 4 :
            print("5*7= ",5*7)
            return 35
    else:
        if timeArray.tm_mon in [2,4,5,7,8,10,11]:
            print(f'{timeArray.tm_mon}在2,4,5,7,8,10,11中,所以输出:',28)
            return 28
        else:
            print(f'{timeArray.tm_mon}在3,6,9,12中,所以输出:',35)
            return 35

DateJudge('03272022')



posted @ 2022-03-27 16:17  半个程序猿Cohen_Lee  阅读(77)  评论(0编辑  收藏  举报