Date 在约会中去掉空格
定义日期时,输出包含空格:Date 在约会中去掉空格,date,batch-file,cmd,Date,Batch File,Cmd,定义日期时,输出包含空格: set thedateis=20/10/2017 for /F "tokens=1,2,3 delims=/" %%a in ('echo %thedateis%') do set day=%%a & set month=%%b & set year=%%c echo The chosen date is: %thedateis%, Day:.%day%., Month:.%month%., Year:.%year%. 它给了我 The chosen
set thedateis=20/10/2017
for /F "tokens=1,2,3 delims=/" %%a in ('echo %thedateis%') do set day=%%a & set month=%%b & set year=%%c
echo The chosen date is: %thedateis%, Day:.%day%., Month:.%month%., Year:.%year%.
它给了我
The chosen date is: 20/10/2017, Day:.20 ., Month:.10 ., Year:.2017.
我怎样才能去掉空格?这是解决方案(感谢@LS)_ᴅᴇᴠ) 而且效果非常好:
set thedateis=11/12/2017
for /F "tokens=1,2,3 delims=/ " %%a in ('echo %thedateis%') do (
set day=%%a
set month=%%b
set year=%%c
)
echo The chosen date is: %thedateis%, Day:.%day%., Month:.%month%., Year:.%year%.
这是因为您自己添加了空格,并且没有将字符串与符号分隔开
For/F“Tokens=1-3Delims=/”(“%thedateis%”)中的%%A设置“day=%A”并设置“month=%B”并设置“year=%C”
编辑
您需要学习使用以下最佳实践符号:
设置“variableName=variableValue”
您仍然需要学习最佳实践并使用以下符号:设置“日期=2017年11月12日”
,设置“日期=%%a”
,设置“月份=%%b”
和设置“年份=%%c”
。