Command Prompt/Bat file - Create new folder named with today's date

后端 未结 4 1064
误落风尘
误落风尘 2020-12-17 03:32

I use the following code to create a new folder that is named with todays date:

for /f \"tokens=1* delims=\" %%a in (\'date /T\') do set datestr=%%a
mkdir c:         


        
4条回答
  •  無奈伤痛
    2020-12-17 04:24

    %date% depends on your computer settings, and locale. Here is a reliable way to get a date and time stamp. Win XP pro and above.

    If you need to use your batch file on unknown machines then this is worth using.

    :: time and date stamp YYYYMMDD, HHMMSS and YYYY-MM-DD_HH-MM-SS
    @echo off
    for /f "delims=" %%a in ('wmic OS Get localdatetime  ^| find "."') do set dt=%%a
    set datestamp=%dt:~0,8%
    set timestamp=%dt:~8,6%
    set YYYY=%dt:~0,4%
    set MM=%dt:~4,2%
    set DD=%dt:~6,2%
    set HH=%dt:~8,2%
    set Min=%dt:~10,2%
    set Sec=%dt:~12,2%
    
    set stamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%
    echo stamp: "%stamp%"
    echo datestamp: "%datestamp%"
    echo timestamp: "%timestamp%"
    
    pause
    

提交回复
热议问题