0

我想在批处理程序中为日期添加一个后缀。

这是我相信会起作用的(如果做得好的话),也是我需要帮助的!

if %date:~0,-8%==01 set "newdateday1=1st" if %date:~0,-8%==02 set "newdateday2=2nd" if %date:~0,-8%==03 set "newdateday3=3rd" if %date:~0,-8% gtr 4 set "newdateday4plus=th"

所以总结一下我需要的是这样的输出

2017 年 8 月 21 日

而不是这个

21-08-2017

因为我认为第一个看起来更好:)

4

1 回答 1

0

只需使用这样的东西:

@Echo Off

Rem Echo This script is based upon a default date format ending dd/MM/yyyy
Rem Echo Where "/" can be any usual separator and leading 0s are included.

Set "ToD=%DATE%"
Set "DoM=%ToD:~-10,2%"
Set "MoY=%ToD:~-7,2%"
Set "Yr=%ToD:~-4%"

If Not "%DoM:~,1%"=="1" (
    If "%DoM:~-1%"=="1" Set "DaS=%DoM%st"
    If "%DoM:~-1%"=="2" Set "DaS=%DoM%nd"
    If "%DoM:~-1%"=="3" Set "DaS=%DoM%rd")
If Not Defined DaS Set "DaS=%DoM%th"
If "%DaS:~,1%"=="0" Set "DaS=%DaS:~1%"

If Not "%MoY:~,1%"=="1" (
    If "%MoY:~-1%"=="1" Set "MaS=%MoY%st"
    If "%MoY:~-1%"=="2" Set "MaS=%MoY%nd"
    If "%MoY:~-1%"=="3" Set "MaS=%MoY%rd")
If Not Defined MaS Set "MaS=%MoY%th"
If "%MaS:~,1%"=="0" Set "MaS=%MaS:~1%"

If Not "%Yr:~-2,1%"=="1" (
    If "%Yr:~-1%"=="1" Set "YaS=%Yr%st"
    If "%Yr:~-1%"=="2" Set "YaS=%Yr%nd"
    If "%Yr:~-1%"=="3" Set "YaS=%Yr%rd")
If Not Defined YaS Set "YaS=%Yr%th"

Echo Today is the %DaS% day of the %MaS% month of the %YaS% year

Timeout -1
于 2017-08-21T09:57:01.833 回答