我如何将数字更改为我想要的格式的命名月份,例如11月



我正在使用以下批处理脚本

echo on
for /f "skip=1" %%x in ('wmic os get localdatetime') do if not defined MyDate set MyDate=%%x
set today=%MyDate:~0,4%-%MyDate:~4,2%-%MyDate:~6,2%
set "_year=%MyDate:~0,4%"
set "_month=%MyDate:~4,2%"
set "_day=%MyDate:~6,2%"
REN "C:Year 2020Oct'2020Data_Sept'2020.xlsx" "Data_%_month%'%_year%.xlsx"

我得到Data_11'2020的输出,而我希望输出是Data_Nov'2020

for %%c in (12,Dec,11,Nov,10,Oct,09,Sep,08,Aug,07,Jul,06,Jun,05,May,04,Apr,03,Mar,02,Feb,01,Jan) do if not defined _month (set "_month=%%c"&goto converted) else if %%c==%_month% set "_month="
:converted

请注意,您也可以使用扩展列表

,9,Sep,8,Aug,7,Jul,6,Jun,5,May,4,Apr,3,Mar,2,Feb,1,Jan

以满足您可能有一位_month的情况

事实上,您可以将其用作通用的";将一个字符串转换为另一个字符串";常规

最新更新