![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-08-08 22:24 |
47,811 topics / 349,895 posts / today 0 new / 48,253 members |
| DOS批处理 & 脚本技术(批处理室) » [Original] ********Simple Solar Terms Calendar******** |
| Printable Version 2,358 / 17 |
| Floor1 s11ss | Posted 2007-09-29 16:01 |
| 银牌会员 Posts 566 Credits 2,098 | |
| Floor2 knoppix7 | Posted 2007-09-29 17:30 |
| 银牌会员 Posts 634 Credits 1,287 From cmd.exe | |
|
I also wrote one ~~~~~~~~~~~~~
@echo off setlocal enabledelayedexpansion :{ ://Process months set Y=%date:~0,4% set M=%date:~5,2% set D=%date:~8,2% if %M:~0,1%==0 set M=%M:~1,1% if %D:~0,1%==0 set D=%D:~1,1% FOR %%i IN (4 400) DO ( set /a T1=%y%%%%%i if !T1!==0 (set runnian=1) ELSE set runnian=0 ) call :checkmouth %runnian% set T1=%Y:~0,2% set T2=%Y:~2,2% if %T2:~0,1%==0 set T2=%T2:~1,1% set /a T1=%T1%%%4 set /a T1=T1/-2+5 set /a T2=((%T2%-%t2%%%4)/4+%T2%)%%7 call :yueyushu set /a T4=(%T1%+%T2%+%T3%+1)%%7 rem T4=Week number, 0=>Sunday 1=>Monday .... set T1=&set T2=&set T3=&set Y= :} :{ ://Display preparation call :setdateend %M% set /a dateend=%dateend%+%T4%-1 set T1=1 for /L %%i IN (0,1,38) DO ( if %%i GEQ %T4% IF %%i LEQ %dateend% ( if !T1! LEQ 9 (set W%%i= !T1! ) ELSE set W%%i=!T1! if !T1! EQU %D% set W%%i=!T1!* call set T5=%%js9!T1!%% if NOT "!T5!"=="" ( if !T1! LEQ 9 (set W%%i= !T1!$) ELSE set W%%i=!T1!$ if !T1! EQU %D% ( if !T1! LEQ 9 (set W%%i= !T1!#) ELSE set W%%i=!T1!# ) ) set /a T1=!T1!+1 ) if %%i LSS %T4% set "W%%i= " if %%i GTR %dateend% set "W%%i= " ) set T1= echo Today is: %date% echo Sun Mon Tue Wed Thu Fri Sat echo %W0% %W1% %W2% %W3% %W4% %W5% %W6% echo %W7% %W8% %W9% %W10% %W11% %W12% %W13% echo %W14% %W15% %W16% %W17% %W18% %W19% %W20% echo %W21% %W22% %W23% %W24% %W25% %W26% %W27% echo %W28% %W29% %W30% %W31% %W32% %W33% %W34% echo %W35% %W36% %W37% %W38% GOTO :EOF :} :{ ://Sub-block part :setdateend for %%i IN (1 3 5 7 8 10 12) DO ( if %1==%%i (set dateend=31) ELSE set dateend=30 ) if %1==2 ( If %runnian%==1 (set dateend=29) ELSE set dateend=28 ) GOTO :EOF :yueyushu set T3=!%m%y! goto :EOF :checkmouth if %1==0 ( set 1y=1 set 2y=4 ) ELSE ( set 1y=0 set 2y=3 ) set 3y=4 set 4y=0 set 5y=2 set 6y=5 set 7y=0 set 8y=3 set 9y=6 set 10y=1 set 11y=4 set 12y=8 GOTO :EOF :} |
|
| Floor3 wudixin96 | Posted 2007-09-29 17:32 |
| 银牌会员 Posts 931 Credits 1,928 | |
|
A showdown between experts, sparking intense interaction
|
|
| Floor4 knoppix7 | Posted 2007-09-29 17:55 |
| 银牌会员 Posts 634 Credits 1,287 From cmd.exe | |
|
It's a pity that his method is much simpler than mine~~
|
|
| Floor5 s11ss | Posted 2007-09-29 23:01 |
| 银牌会员 Posts 566 Credits 2,098 | |
Originally posted by knoppix7 at 2007-9-29 05:55 PM: knoppix7, there seems to be a problem with your leap year judgment. Do you mean that only those divisible by 400 are leap years? You can test it with 2004-2-29.........2004 is obviously a leap year |
|
| Floor6 lipu721 | Posted 2007-09-29 23:50 |
| 新手上路 Posts 2 Credits 4 | |
|
Dizzy...
|
|
| Floor7 lipu721 | Posted 2007-09-29 23:50 |
| 新手上路 Posts 2 Credits 4 | |
|
It's dizzying just looking at it, there are too many. I'm dizzy
|
|
| Floor8 knoppix7 | Posted 2007-09-30 12:36 |
| 银牌会员 Posts 634 Credits 1,287 From cmd.exe | |
|
Only divisible by 4 or 400.
Got it. The calculation program was wrong... Need to change FOR %%i IN (4 400) DO ( set /a T1=%y%%%%%i if !T1!==0 (set runnian=1) ELSE set runnian=0 ) to set runnian=0 FOR %%i IN (4 400) DO ( set /a T1=%y%%%%%i if !T1!==0 (set runnian=1) ) [ Last edited by knoppix7 on 2007-9-30 at 04:45 PM ] |
|
| Floor9 knoppix7 | Posted 2007-09-30 16:46 |
| 银牌会员 Posts 634 Credits 1,287 From cmd.exe | |
|
As a return for DEBUG. Add 4 points.
|
|
| Floor10 s11ss | Posted 2007-09-30 17:23 |
| 银牌会员 Posts 566 Credits 2,098 | |
|
knoppix7,
There is a problem with the algorithm you used to judge leap years. I used to be completely confused about judging leap years. The statement "A year divisible by 4 or 400 is a leap year" is equivalent to saying that a year divisible by 4 is a leap year, because a number divisible by 400 is a sufficient condition for the number to be divisible by 4. It's like saying: A woman with big eyes or a woman with big eyes and long hair is a beauty. Actually, it means that a woman with big eyes is a beauty. The correct algorithm should be: A year divisible by 4 but not by 100 is a leap year; or a year divisible by 400 is a leap year. For example, the year 2100 would be a leap year according to your algorithm, but actually it is not because it does not satisfy either of the above two conditions. But actually, a year divisible by 3200 is not a leap year, but that's too far from now. Generally, the above algorithm is used to judge leap years. I didn't understand the judgment of leap years when I studied C language a few years ago. I finally fully understood it when I wrote this perpetual calendar recently. |
|
| Floor11 slore | Posted 2007-09-30 17:31 |
| 铂金会员 Posts 2,478 Credits 5,212 | |
|
Actually, the statement that "what is divisible by 3200 is not a leap year" is too... Don't make it lead to the idea that the opposite is a leap year...
A year divisible by 4 but not by 100 is a leap year; or a year divisible by 400 is a leap year. This is correct. Reason: To determine which year in the solar calendar is a leap year, you just need to do a simple calculation. Divide the year of the solar calendar by 4. If it is divisible, it is a leap year. For example, 1964, 1968, etc., are all leap years, and February of these years has 29 days. Also, because the actual number of days in a solar year is 365 days 5 hours 48 minutes 46 seconds, which is 5 hours 48 minutes 46 seconds more than the common year of 365 days. Over four years, it only adds up to 23 hours 15 minutes 4 seconds. If we add one day every 4 years for a leap year, we add an extra 44 minutes 56 seconds. In about 400 years, it will add about 3 days. So, we have set an additional rule: For years that are full centuries in the solar calendar, such as AD 1800, 1900, 2000, etc., only those divisible by 400 are considered leap years. Therefore, although AD 1800 and 1900 are divisible by 4, they are not divisible by 400, so they are not considered leap years, while AD 2000 is a leap year, and February of it has 29 days. With this additional rule, we can subtract those 3 extra days over 400 years. Although there will still be a slight error after such adjustment, it will take 3000 years to be off by one day, which is very accurate for our daily application. |
|
| Floor12 knoppix7 | Posted 2007-09-30 17:59 |
| 银牌会员 Posts 634 Credits 1,287 From cmd.exe | |
Originally posted by s11ss at 2007-9-30 05:23 PM: I'm sorry. I specifically copied the method from the internet. However, I noticed that the time in WXP doesn't reach the year 2100. So I didn't include it. |
|
| Floor13 knoppix7 | Posted 2007-09-30 18:04 |
| 银牌会员 Posts 634 Credits 1,287 From cmd.exe | |
Originally posted by slore at 2007-9-30 05:31 PM: What is the calculation method... There's no way to specify the time manually... |
|
| Floor14 knoppix7 | Posted 2007-09-30 18:07 |
| 银牌会员 Posts 634 Credits 1,287 From cmd.exe | |
|
I've got it.
Judge with the date command. Example: C:\Documents and Settings\lenovo>date 2007-02-29(Not a leap year, so...) The system cannot accept the entered date. Enter new date: (year month day) C:\Documents and Settings\lenovo>date 2100-02-29(Exceeds the year limit of WXP) The system cannot accept the entered date. Enter new date: (year month day) C:\Documents and Settings\lenovo>date 2004-02-29(Succeeds) [ Last edited by knoppix7 on 2007-10-1 at 02:11 PM ] |
|
| Floor15 knoppix7 | Posted 2007-10-01 14:13 |
| 银牌会员 Posts 634 Credits 1,287 From cmd.exe | |
|
The method I thought of:
@echo off set DD=%date:~0,10% set runnian=0 date %y%-2-29|find "The system cannot accept the entered date." >nul ||set runnian=1 date %DD% But I didn't test it... |
|
| 1 2 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |