批量添加 st nd rd th to date

add st nd rd th to date in batch

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

This is what I belive would work (if done proper) and is also what I need help with!

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"

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

21st of August 2017

而不是这个

21-08-2017

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

只需使用这样的东西:

@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