从AutoIt的日期函数中找到的算法,在此向此算法的原作者Jos van der Zande致意。此函数的作用是:传递日期参数到函数,返回这一天是一星期中的第几天。- @echo Off
- Call :DateToDayOfWeek 2009 3 18 iDayOfWeek
- Echo %iDayOfWeek%
- Pause & Exit /b 0
- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- :DateToDayOfWeek iYear, iMonth, iDay, ByRef weekday
- :: Returns the weekday number for a given date.
- :: %iYear% - A valid year in format YYYY.
- :: %iMonth% - A valid month in format MM.
- :: %iDay% - A valid day in format DD.
- :: %weekday% - Receives the result.
- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- Set /a numOfParams = 0
- For %%a in (%*) do Set /a numOfParams += 1
- If "%numOfParams%" neq "4" Exit /b 1
- SetLocal EnableExtensions
- Set /a aFactor, yFactor = 0, mFactor = 0, dFactor = 0
- Set /a aFactor = (14 - %~2) / 12, yFactor = %~1 - aFactor
- Set /a mFactor = %~2 + (12 * aFactor) - 2
- Set /a dFactor = 1 + (%~3 + yFactor + yFactor/4 - yFactor/100 + yFactor/400 + 31 * mFactor/12) %% 7
- EndLocal & Set "%~4=%dFactor%" & Exit /b 0
复制代码
|