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

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

    This is what I've used:

    ::Date Variables - replace characters that are not legal as part of filesystem file names (to produce name like "backup_04.15.08.7z")
    SET DT=%date%
    SET DT=%DT:/=.%
    SET DT=%DT:-=.%
    

    If you want further ideas for automating backups to 7-Zip archives, I have a free/open project you can use or review for ideas: http://wittman.org/ziparcy/

提交回复
热议问题