用bat脚本计算前一天时间
时间: 2023-04-03 12:03:01 浏览: 112
可以使用以下代码计算前一天的日期:
```
@echo off
setlocal enabledelayedexpansion
set "today=%date%"
set /a "day=1%today:~0,2%-100"
set /a "month=1%today:~3,2%-100"
set /a "year=today:~6,4%"
set /a "days=0"
if %month% equ 1 (
set /a "days=31"
) else if %month% equ 2 (
if %year% equ 0 (
set /a "days=29"
) else if %year% mod 4 equ 0 (
if %year% mod 100 neq 0 (
set /a "days=29"
) else if %year% mod 400 eq 0 (
set /a "days=29"
) else (
set /a "days=28"
)
) else (
set /a "days=28"
)
) else if %month% equ 3 (
set /a "days=31"
) else if %month% equ 4 (
set /a "days=30"
) else if %month% equ 5 (
set /a "days=31"
) else if %month% equ 6 (
set /a "days=30"
) else if %month% equ 7 (
set /a "days=31"
) else if %month% equ 8 (
set /a "days=31"
) else if %month% equ 9 (
set /a "days=30"
) else if %month% equ 10 (
set /a "days=31"
) else if %month% equ 11 (
set /a "days=30"
) else if %month% equ 12 (
set /a "days=31"
)
set /a "day=day-1"
if %day% equ 0 (
set /a "month=month-1"
if %month% equ 0 (
set /a "year=year-1"
set /a "month=12"
)
if %month% equ 2 (
if %year% equ 0 (
set /a "days=29"
) else if %year% mod 4 equ 0 (
if %year% mod 100 neq 0 (
set /a "days=29"
) else if %year% mod 400 eq 0 (
set /a "days=29"
) else (
set /a "days=28"
)
) else (
set /a "days=28"
)
)
set /a "day=days"
)
set "month=0%month%"
set "day=0%day%"
set "year=000%year%"
set "month=!month:~-2!"
set "day=!day:~-2!"
set "year=!year:~-4!"
echo %year%%month%%day%
```
这个脚本会获取当前日期,然后计算前一天的日期,并将其输出。注意,这个脚本只能在 Windows 系统上运行。
阅读全文