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

前端 未结 28 2092
别跟我提以往
别跟我提以往 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 05:41

    I note that the o/p did not ask for a region-independent solution. My solution is for the UK though.

    This is the simplest possible solution, a 1-line solution, for use in a Batch file:

    FOR /F "tokens=1-3 delims=/" %%A IN ("%date%") DO (SET today=%%C-%%B-%%A)
    echo %today%
    

提交回复
热议问题