python 检测目标日期是否为当天?


def is_today(target_date):
"""
Detects if the date is current date
:param target_date:
:return: Boolean
"""
# Get the year, month and day
c_year = datetime.datetime.now().year
c_month = datetime.datetime.now().month
c_day = datetime.datetime.now().day

# Disassemble the date
date_list = target_date.split(" ")[0].split("-")
print(date_list)
t_year = int(date_list[0])
t_month = int(date_list[1])
t_day = int(date_list[2])

final = False
if c_year == t_year and c_month == t_month and c_day == t_day:
final = True
print(final)
return final


is_today('2020-12-15')


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM