Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Date 在约会中去掉空格_Date_Batch File_Cmd - Fatal编程技术网

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”