@echo off
setlocal enabledelayedexpansion
echo generate last datetime...
set todayyear=%date:~0,4%
set todaymon=%date:~5,2%
set todayday=%date:~8,2%
if "!todayday!" == "08" set todayday=8
if "!todayday!" == "09" set todayday=9
set lastdayyear=
set lastdaymon=
set lastdayday=
set lastdayyear=%todayyear%
set lastdaymon=%todaymon%
set /a lastdayday=todayday-1
echo %todayday%
echo %lastdayday%
if "%lastdayday%" == "0" (
if "!lastdaymon!" == "01" (
set lastdaymon=12
set /a lastdayyear-=1
) else (
set /a lastdaymon-=1
if "!lastdaymon!" == "1" set lastdaymon=01
if "!lastdaymon!" == "2" set lastdaymon=02
if "!lastdaymon!" == "3" set lastdaymon=03
if "!lastdaymon!" == "4" set lastdaymon=04
if "!lastdaymon!" == "5" set lastdaymon=05
if "!lastdaymon!" == "6" set lastdaymon=06
if "!lastdaymon!" == "7" set lastdaymon=07
if "!lastdaymon!" == "8" set lastdaymon=08
if "!lastdaymon!" == "9" set lastdaymon=09
)if "!lastdaymon!" == "01" set lastdayday=31
if "!lastdaymon!" == "03" set lastdayday=31
if "!lastdaymon!" == "04" set lastdayday=30
if "!lastdaymon!" == "05" set lastdayday=31
if "!lastdaymon!" == "06" set lastdayday=30
if "!lastdaymon!" == "07" set lastdayday=31
if "!lastdaymon!" == "08" set lastdayday=31
if "!lastdaymon!" == "09" set lastdayday=30
if "!lastdaymon!" == "10" set lastdayday=31
if "!lastdaymon!" == "11" set lastdayday=30
if "!lastdaymon!" == "12" set lastdayday=31
if "!lastdaymon!" == "02" (
set isleapyear=
set /a isleapyear=!lastdayyear!%%400
if "!isleapyear!" == "0" (
set lastdayday=29
goto makelastdate
)set /a isleapyear=!lastdayyear!%%100
if "!isleapyear!" == "0" (
set lastdayday=28
goto makelastdate
)set /a isleapyear=!lastdayyear%%4
if "!isleapyear!" == "0" (
set lastdayday=29
goto makelastdate
) else (
set lastdayday=28
goto makelastdate))
):makelastdate
if "%lastdayday%" == "1" set lastdayday=01
if "%lastdayday%" == "2" set lastdayday=02
if "%lastdayday%" == "3" set lastdayday=03
if "%lastdayday%" == "4" set lastdayday=04
if "%lastdayday%" == "5" set lastdayday=05
if "%lastdayday%" == "6" set lastdayday=06
if "%lastdayday%" == "7" set lastdayday=07
if "%lastdayday%" == "8" set lastdayday=08
if "%lastdayday%" == "9" set lastdayday=09
rem 該程式有bug 下面幾句話進行修正8月1號和9月1號的日期
if !todaymon!==08 if !todayday!==01 set lastdaymon=07
if !todaymon!==08 if !todayday!==01 set lastdayday=31
if !todaymon!==09 if !todayday!==01 set lastdaymon=08
if !todaymon!==09 if !todayday!==01 set lastdayday=31
set lastdate=%lastdayyear%%lastdaymon%%lastdayday%
@echo today =%date:~0,4%%date:~5,2%%date:~8,2%
@echo yestoday=%lastdate%
pause
Windows下批處理對拍程式
echo off again data input 生成隨機輸入 aoutput.a boutput.b fc output.a output.b 比較檔案 ifnot errorlevel 1 goto again 相同時繼續迴圈注 以上部分來自演算法競賽入門經典第二版附錄 再來乙個卿爺的對拍程式...
常用的Windows批處理
切換執行路徑如果不換盤的話 cd 換盤 cd d 獲取當前日期 編寫windows批處理時經常會需要使用到日期和時間作為檔名,所以是非常重要的。如何獲取日期呢?格式 date 結果 2012 07 31 如何獲取時間呢?格式 time 結果 10 21 21.68 這是獲取的系統標準格式的日期和時間...
Windows批處理(一)
批處理是一系列可執行的命令集合揉成的乙個檔案,有點類似於日常開發中的乙個類。window平台下批處理副檔名一般為bat或者cmd 先介紹幾個簡單的命令 這是注釋命令,和開發中的 效果是一樣的,都是單行注釋。有效標號 冒號後面跟乙個變數字串,一般用於goto語句的跳轉。例如 functiona 和 a...