bat脚本获取前一天的日期
时间: 2023-04-05 08:01:10 浏览: 63
shell中获取n天前的日期
4星 · 用户满意度95%
可以使用以下代码获取前一天的日期:
```
@echo off
setlocal enabledelayedexpansion
set "today=%date%"
set /a "day=1"
set "year=!today:~0,4!"
set "month=!today:~5,2!"
set "day=!today:~8,2!"
if %day% leq %day% set /a "month-=1"
if !month! equ 0 set /a "year-=1" & set "month=12"
if !month! equ 2 (
if !year! equ 1900 (
set /a "day=28"
) else if !year! equ 1800 (
set /a "day=28"
) else if !year! equ 1700 (
set /a "day=28"
) else if !year! equ 1600 (
set /a "day=29"
) else if !year! equ 1500 (
set /a "day=28"
) else if !year! equ 1400 (
set /a "day=28"
) else if !year! equ 1300 (
set /a "day=28"
) else if !year! equ 1200 (
set /a "day=29"
) else if !year! equ 1100 (
set /a "day=28"
) else if !year! equ 1000 (
set /a "day=28"
) else if !year! equ 900 (
set /a "day=28"
) else if !year! equ 800 (
set /a "day=29"
) else if !year! equ 700 (
set /a "day=28"
) else if !year! equ 600 (
set /a "day=28"
) else if !year! equ 500 (
set /a "day=28"
) else if !year! equ 400 (
set /a "day=29"
) else if !year! equ 300 (
set /a "day=28"
) else if !year! equ 200 (
set /a "day=28"
) else if !year! equ 100 (
set /a "day=28"
) else if !year! equ 0 (
set /a "day=28"
) else (
set /a "day=29"
)
) else if !month! equ 4 (
set /a "day=30"
) else if !month! equ 6 (
set /a "day=30"
) else if !month! equ 9 (
set /a "day=30"
) else if !month! equ 11 (
set /a "day=30"
) else (
set /a "day=31"
)
if !month! lss 10 set "month=0!month!"
if !day! lss 10 set "day=0!day!"
set "yesterday=!year!!month!!day!"
echo %yesterday%
```
这段代码会获取当前日期,然后计算前一天的日期,并输出前一天的日期。
阅读全文