程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Determine whether today is the last Monday of the current month Python

編輯:Python

What you find on the Internet is positive thinking , I feel a little in trouble , and java Mostly , I am java Not good. , Not familiar with java Date calendar module , I have to find my own way

demand

A script that is executed once a day , You need to send a message on the last Monday of each month

Method

1.crontab There seems to be no such expression in ( Reference :https://zhuanlan.zhihu.com/p/38130334)

Not all of them , I only read what I needed , I don't know linux Different systems , still crontab Different versions , This deploy In my system (debian) It's a grammatical error

2. So you can only use python 了 , Judge for yourself in the script

Ideas

Today's date is known , Reverse judgment

Codes and notes

# Judge whether today is the last Monday of the current month 
import datetime
import calendar
def isLastMonday():
# Get current year 
year = datetime.date.today().year
# Get current month 
month = datetime.date.today().month
today = datetime.date.today().day
dayOfWeek = datetime.datetime.now().weekday()
weekDay,monthCountDay = calendar.monthrange(year,month)
# Judge whether today is Monday (dayOfWeek=0)
# If you are judging whether it is the last Monday (+7, Is it greater than the last day )
if dayOfWeek == 0:
if today+7 > monthCountDay:
print " The last Monday "
return True
return False

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved