| @echo off&setlocal enabledelayedexpansion |
| :begin |
| color 0e |
| mode con cols=65 lines=26 |
| set n=0 |
| for /f "tokens=1-4" %%i in (city.txt) do ( |
| if not "!country!" equ "%%i" ( |
| set /a n+=1 |
| set "t!n!-1=%%i %%j" |
| set country=%%i |
| set m=1 |
| ) else ( |
| set /a m+=1 |
| set "t!n!-!m!=%%i %%j" |
| ) |
| ) |
| for /f "tokens=1-3 delims=- " %%i in ("%date%") do ( |
| set year=%%i |
| set /a month=1%%j-100 |
| set /a day=1%%k-100 |
| ) |
| set "days=312831303130313130313031" |
| set /a ok="^!(year%%4) & ^!(^!(year%%100)) | ^!(year%%400)" |
| if !ok! equ 1 set days=!days:3128=3129! |
| set time1=%time% |
| set time2=%time% |
| if "%time1:~,1%" equ " " (set time1=%time:~1,1%) else set time1=%time:~,2% |
| :code |
| cls |
| echo. |
| echo ╭────────╮ |
| echo ╭────────┤ 世界时间查看器 ├────────╮ |
| echo │ ╰────────╯ │ |
| echo │ │ |
| echo │ 本程序的功能为查询世界各地主要城市当前日期与 │ |
| echo │ │ |
| echo │ 时间,采用算法为区时计算法。输入dir即可查看各个国 │ |
| echo │ │ |
| echo │ 家城市的代号,输入代号即可查看各地时间。代号位于 │ |
| echo │ │ |
| echo │ 每个城市的后面。例如输入57-12即可查看[美国]洛杉矶 │ |
| echo │ │ |
| echo │ 的当前时间。 │ |
| echo │ │ |
| echo │ 已考虑到闰年二月份多一天以及月底加一天与月初 │ |
| echo │ │ |
| echo │ 减一天的情况,请大家测试。 │ |
| echo │ │ |
| echo │ code by lhjoanna │ |
| echo │ │ |
| echo ╰──────────────────────────╯ |
| echo. |
| set /p code=请输入要查询的国家城市的代号: |
| if "%code%" equ "dir" ( call :display &echo.&echo.&goto code ) |
| call set "str=%%t!code!%%" |
| for /f "tokens=3,4" %%i in ('findstr "%str%" city.txt 2^>nul') do ( |
| set /a result=time1+%%j |
| if !result! lss 0 ( |
| set /a result+=24 |
| if not !day! equ 1 ( set /a day-=1 ) else ( |
| if not !month! equ 1 ( |
| set /a month-=1 |
| set /a x=month*2-2 |
| set day=!days:~%x%,2! |
| ) else set month=12&set day=31&set /a year-=1 |
| ) |
| ) else ( |
| if !result! geq 24 ( |
| set /a result-=24 |
| set /a y=month*2-2 |
| set day_=!day:~%y%,2! |
| if not !day! equ !day_! (set /a day+=1) else ( |
| if not !month! equ 12 ( set /a month+=1&set day=1) else set month=1&set |
| day=1&set /a year+=1 |
| ) |
| ) |
| ) |
| echo.&echo %str% 现在时间为:!year!-!month!-!day! !result!%time2:~2% |
| ) |
| pause>nul |
| goto begin |
| :display |
| cls |
| set n=0 |
| for /f "tokens=1-4" %%i in (city.txt) do ( |
| if not "!country!" equ "%%i" ( |
| set /a n+=1 |
| echo. |
| set /p=【!n!】%%i:%%j!n!-1 <nul |
| set "t!n!-1=%%i %%j" |
| set country=%%i |
| set m=1 |
| ) else ( |
| set /a m+=1 |
| set /p=%%j!n!-!m! <nul |
| set "t!n!-!m!=%%i %%j" |
| ) |
| for %%a in (20 41 60 80 101) do ( |
| if !n! equ %%a pause>nul&cls |
| ) |
| ) |
| goto :eofCOPY |