How do I get current date/time on the Windows command line in a suitable format for usage in a file/folder name?

前端 未结 28 2159
别跟我提以往
别跟我提以往 2020-11-21 05:28

Update: Now that it\'s 2016 I\'d use PowerShell for this unless there\'s a really compelling backwards-compatible reason for it, particularly because of the regional setting

28条回答
  •  伪装坚强ぢ
    2020-11-21 06:00

    Short answer :

     :: Start - Run , type:
     cmd /c "powershell get-date -format ^"{yyyy-MM-dd HH:mm:ss}^"|clip"
    
     :: click into target media, Ctrl + V to paste the result 
    

    Long answer

        @echo off
        :: START USAGE  ==================================================================
        ::SET THE NICETIME 
        :: SET NICETIME=BOO
        :: CALL GetNiceTime.cmd 
    
        :: ECHO NICETIME IS %NICETIME%
    
        :: echo nice time is %NICETIME%
        :: END USAGE  ==================================================================
    
        echo set hhmmsss
        :: this is Regional settings dependant so tweak this according your current settings
        for /f "tokens=1-3 delims=:" %%a in ('echo %time%') do set hhmmsss=%%a%%b%%c 
        ::DEBUG ECHO hhmmsss IS %hhmmsss%
        ::DEBUG PAUSE
        echo %yyyymmdd%
            :: this is Regional settings dependant so tweak this according your current settings
        for /f "tokens=1-3 delims=." %%D in ('echo %DATE%') do set  yyyymmdd=%%F%%E%%D
        ::DEBUG ECHO yyyymmdd IS %yyyymmdd%
        ::DEBUG PAUSE
    
    
        set NICETIME=%yyyymmdd%_%hhmmsss%
        ::DEBUG echo THE NICETIME IS %NICETIME%
    
        ::DEBUG PAUSE
    

提交回复
热议问题