Batch command date and time in file name

前端 未结 14 2402
闹比i
闹比i 2020-11-22 01:25

I am compressing files using WinZip on the command line. Since we archive on a daily basis, I am trying to add date and time to these files so that a new one is auto generat

14条回答
  •  情书的邮戳
    2020-11-22 01:55

    You should search; you can simply replace all spaces with zero set hr=%hr: =0%jeb Oct 11 '11 at 14:16

    So I did:

    set hr=%time:~0,2%
    set hr=%hr: =0%
    

    Then use %hr% inside whatever string you are formatting to always get a two-digit hour.

    (Jeb's comment under the most popular answer worked the best for me and is the simplest. I repost it here to make it more obvious for future users.)

提交回复
热议问题