简体   繁体   中英

Windows batch: date format variable not printing correctly

So i have this code.

FOR /F "tokens=*" %%A IN ('dateFormat +"%Y/%m/%d %T"') DO SET Now=%%A
CALL run_some_job "%Now%"

my output.

JOB_FILE_PATH>FOR /F "tokens=*" %A IN ('dateFormat +"m/T"
') DO SET Now=%A

JOB_FILE_PATH>SET Now=m/T

JOB_FILE_PATH>CALL run_some_job  m/T

I use the dateFormat tool from date.exe in this. http://unxutils.sourceforge.net/ to print date. If i do dateFormat +"%Y/%m/%d %T", than it works correctly.

Thanks

您需要在日期格式参数中转义百分号:

FOR /F "tokens=*" %%A IN ('c:\utils\date +"%%Y/%%m/%%d %%T"') DO SET Now=%%A

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM