正确
可以把多余的代码删除了:
echo %Today%
echo %FileDay%
echo %MinusD%
echo %MinusT%
可以把多余的代码删除了:
echo %Today%
echo %FileDay%
echo %MinusD%
echo %MinusT%
联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!
@echo off
set SrcFile=D:\a.txt
set Today=
set FileDay=
set MinusD=
set MinusT=
set Today=%date:~4,4%%date:~9,2%%date:~12,2%%time:~15,2%%time:~18,2%
for /f "skip=5 tokens=1-2 delims= " %%a in ('dir /tw %SrcFile%') do (
set FileDay=%%a%%b
goto :compare
)
:compare
set FileDayT=%FileDay%
set FileDay=%FileDay:~0,4%%FileDay:~5,2%%FileDay:~8,2%%FileDay:~12,2%%FileDay:~15,2%
set /a MinusD=%Today:~0,8%-%FileDay:~0,8%
set /a MinusT=1%Today:~8,4%-1%FileDay:~8,4%
if "%FileDayT:~-1%" equ "p" (
set /a MinusT-=1200
)
if %MinusD% leq 0 (
if %MinusT% gtr 5 (
echo "The system is down"
) else (
echo "The system is running"
)
) else (
echo "The system is down"
)
pause@echo off
set SrcFile=D:\a.txt
for /f "skip=5 tokens=1-2 delims= " %%a in ('dir /tw "%SrcFile%"') do (
set "FileDay=%%a %%b"
goto :compare
)
:compare
REM set "FileDay=2008/11/25 20:57"
call :DateToMins %FileDay:~0,4% %FileDay:~5,2% %FileDay:~8,2% %FileDay:~11,2% %FileDay:~14,3% mFileDay
echo FileDay: %FileDay:~0,4% %FileDay:~5,2% %FileDay:~8,2% %FileDay:~11,2% %FileDay:~14,3% mFileDay
echo FileDay2Minutes: %mFileDay%
REM set "mydate=星期二 2008/11/25 15:53:54.40"
set Today=%date:~4,4%%date:~9,2%%date:~12,2%%time:~15,2%%time:~18,2%
call :DateToMins %mydate:~4,4% %mydate:~9,2% %mydate:~12,2% %mydate:~15,2% %mydate:~18,2% mToday
echo Today: %mydate:~4,4% %mydate:~9,2% %mydate:~12,2% %mydate:~15,2% %mydate:~18,2% mToday
echo Today2Minutes: %mToday%
set /a mMinus=mToday-mFileDay
echo Minus: %mMinus%
if %mMinus% gtr 5 (
echo "The system is down"
) else (
echo "The system is running"
)
pause
goto :eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:DateToMins %yy% %mm% %dd% %hh% %mm% result
::
:: By: Ritchie Lawrence, updated 2003-04-03. Version 1.1
::
:: Func: Returns the number of elapsed minutes since 1970-01-01 00:00
:: for a given date. For NT4/2K/XP/2003
::
:: Args: %1 years to convert, 2 or 4 digit (by val)
:: %2 months to convert, 1/01 to 12, leading zero ok (by val)
:: %3 days to convert, 1/01 to 31, leading zero ok (by val)
:: %4 hours to convert, 1/01 to 12 for 12hr times (minutes must be
:: suffixed by 'a' or 'p', 0/00 to 23 for 24hr clock (by val)
:: %5 mins to convert, 00-59 only, suffixed by a/p if 12hr (by val)
:: %6 var to receive number of elapsed minutes (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
set yy=%1&set mm=%2&set dd=%3&set hh=%4&set nn=%5
if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%)
set /a dd=100%dd%%%100,mm=100%mm%%%100
set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2
set /a j=j/5+dd+y*365+y/4-y/100+y/400-2472633
if 1%hh% LSS 20 set hh=0%hh%
if {%nn:~2,1%} EQU {p} if "%hh%" NEQ "12" set hh=1%hh%&set/a hh-=88
if {%nn:~2,1%} EQU {a} if "%hh%" EQU "12" set hh=00
if {%nn:~2,1%} GEQ {a} set nn=%nn:~0,2%
set /a hh=100%hh%%%100,nn=100%nn%%%100,j=j*1440+hh*60+nn
endlocal&set %6=%j%&goto :EOF@echo off
set SrcFile=D:\a.txt
for /f "skip=5 tokens=1-2 delims= " %%a in ('dir /tw "%SrcFile%"') do (
set "FileDay=%%a %%b"
goto :compare
)
:compare
REM set "FileDay=2008/11/25 20:57"
call :DateToMins %FileDay:~0,4% %FileDay:~5,2% %FileDay:~8,2% %FileDay:~11,2% %FileDay:~14,3% mFileDay
echo FileDay: %FileDay:~0,4% %FileDay:~5,2% %FileDay:~8,2% %FileDay:~11,2% %FileDay:~14,3% mFileDay
echo FileDay2Minutes: %mFileDay%
REM set "mydate=星期二 2008/11/25 15:53:54.40"
call :DateToMins %date:~4,4% %date:~9,2% %date:~12,2% %time:~15,2% %time:~18,2% mToday
echo Today: %date:~4,4% %date:~9,2% %date:~12,2% %time:~15,2% %time:~18,2% mToday
echo Today2Minutes: %mToday%
set /a mMinus=mToday-mFileDay
echo Minus: %mMinus%
if %mMinus% gtr 5 (
echo "The system is down"
) else (
echo "The system is running"
)
pause
goto :eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:DateToMins %yy% %mm% %dd% %hh% %mm% result
::
:: By: Ritchie Lawrence, updated 2003-04-03. Version 1.1
::
:: Func: Returns the number of elapsed minutes since 1970-01-01 00:00
:: for a given date. For NT4/2K/XP/2003
::
:: Args: %1 years to convert, 2 or 4 digit (by val)
:: %2 months to convert, 1/01 to 12, leading zero ok (by val)
:: %3 days to convert, 1/01 to 31, leading zero ok (by val)
:: %4 hours to convert, 1/01 to 12 for 12hr times (minutes must be
:: suffixed by 'a' or 'p', 0/00 to 23 for 24hr clock (by val)
:: %5 mins to convert, 00-59 only, suffixed by a/p if 12hr (by val)
:: %6 var to receive number of elapsed minutes (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
set yy=%1&set mm=%2&set dd=%3&set hh=%4&set nn=%5
if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%)
set /a dd=100%dd%%%100,mm=100%mm%%%100
set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2
set /a j=j/5+dd+y*365+y/4-y/100+y/400-2472633
if 1%hh% LSS 20 set hh=0%hh%
if {%nn:~2,1%} EQU {p} if "%hh%" NEQ "12" set hh=1%hh%&set/a hh-=88
if {%nn:~2,1%} EQU {a} if "%hh%" EQU "12" set hh=00
if {%nn:~2,1%} GEQ {a} set nn=%nn:~0,2%
set /a hh=100%hh%%%100,nn=100%nn%%%100,j=j*1440+hh*60+nn
endlocal&set %6=%j%&goto :EOF