@echo off
setlocal enabledelayedexpansion
::::::::Simple perpetual calendar {s11ss 2007-9-29}::::::::
::Principle: Find out what day of the week the first day of a certain month is, from which we can get what day of the week other days correspond to, and finally display each day by rows.
echo Please input a year and a month,like 2007-9:
echo.
set/p str=
for /f "delims=- tokens=1*" %%a in ('echo %str%') do (
set/a year=%%a
set/a month=%%b
if %%b leq 2 (set/a year-=1 && set/a month+=12)
set y=!year:~-2!
set is0=!y:~0,1!
if !is0! equ 0 set y=!y:~1,1!
set c=!year:~0,-2!
set m=!month!
set d=1
if %%b leq 2 (set/a year+=1 && set/a month-=12)
)
set/a w=(!y!+!y!/4+%c%/4-2*%c%+26*(%m%+1)/10+%d%-1)
::The above comes from Zeller's formula, which is the key to finding out what day of the week the 1st is.
set/a ?=!w!%%7
if !?! lss 0 set/a ?+=7
set/a r4=!year!%%4,r100=!year!%%100,r400=!year!%%400
set/a feb=28
if !r4! equ 0 (if not !r100! equ 0 set/a feb=29)
if !r400! equ 0 set/a feb=29
set/a mseq=1
for %%a in (31,!feb!,31,30,31,30,31,31,30,31,30,31) do (
if !mseq! equ !month! (set/a day=%%a && goto :e)
set/a mseq+=1
)
:e
set s1= 1
for /l %%a in (1,1,!?!) do set s1= !s1!
set/a row=1
set x=!s1!
for /l %%a in (2,1,!day!) do (
if %%a lss 10 (set dseq= %%a) else (set dseq=%%a)
set/a ?+=1
if !?! equ 7 (
set/a ?=0
set s!row!=!x!
set/a row+=1
set x=!dseq!
) else (
set x=!x! !dseq!
)
)
set s!row!=!x!
echo Sun Mon Tue Wed Thu Fri Sat
for /l %%a in (1,1,!row!) do echo !s%%a!
echo.
echo Press Any Key To Exit...
pause>nul
goto :eof
Zeller's Formula
Zeller's (Zeller) formula: is a formula for calculating the day of the week.
For any given date, you can use this formula to calculate what day of the week it is.
The Zeller formula is as follows:
w=y++-2c++d-1
The meanings of the symbols in the formula are as follows:
w: Day of the week; w modulo 7 gives: 0-Sunday, 1-Monday, 2-Tuesday, 3-Wednesday, 4-Thursday, 5-Friday, 6-Saturday
c: Century (first two digits)
y: Year (last two digits)
m: Month (m is greater than or equal to 3 and less than or equal to 14, that is, in Zeller's formula, January and February of a certain year should be regarded as the 13th and 14th months of the previous year. For example, January 1, 2003 should be regarded as January 1, 2002)
d: Day
represents taking the integer part, that is, only the integer part.
The following takes the 100th anniversary of the founding of the People's Republic of China (October 1, 2049) to calculate what day of the week it is. The process is as follows:
w=y++-2c++d-1
=49++-2×20++1-1
=49++5-40+
=49+12+5-40+28
=54 (remainder 5 when divided by 7)
That is, October 1, 2049 (100th anniversary of National Day) is Friday.
Another example: calculate April 4, 2006. The process is as follows:
w=y++-2c++d-1
=6++-2*20++4-1
=-12 (remainder 2 when divided by 7, pay attention to the modulo operation for negative numbers!)
However, the above formula is only suitable for the situation after October 15, 1582 (the 10th year of Wanli in the Ming Dynasty in China). Pope Gregory XIII of Rome organized a group of astronomers in 1582 to calculate data based on Copernicus' heliocentric theory and modified the Julian calendar. The 10 days between October 5 and 14, 1582 were declared void, and October 15 followed October 4.
Later, people called this new calendar the "Gregorian calendar", which is the calendar commonly used in the world today, referred to as the Gregorian calendar or the Gregorian calendar.
Recent Ratings for This Post
( 1 in total)
Click for details
| Rater | Score | Time |
|---|---|---|
| wudixin96 | +9 | 2007-09-29 16:12 |
