Time is set incorrectly after midnight

后端 未结 4 713
逝去的感伤
逝去的感伤 2020-11-27 23:11

i am using the following to set the date/time to something more readable:

set day=%date:~4,2%
set mth=%date:~7,2%
set yr=%date:~10,4%
set hur=%time:~0,2%
set         


        
4条回答
  •  余生分开走
    2020-11-27 23:41

    set "day=%date:~4,2%"
    set "mth=%date:~7,2%"
    set "yr=%date:~10,4%"
    set "_time=0%time%"
    set "hur=%_time:~-11,2%"
    set "min=%_time:~-8,2%"
    set bdate=[%day%-%mth%-%yr%]-[%hur%-%min%]
    

    You can pad time with a 0 and then do the substitution from the right side using negative numbers as the start position of the string. 1:00 would become 01-00 to match the pattern of HH-MM.

提交回复
热议问题