我想在批处理程序中为日期添加后缀。
这是我相信的工作(如果做得好),也是我需要帮助的地方!
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
在我看来,第一种看起来更好:)
答案 0 :(得分: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