2022-03-25 BAT批处理命令time取时间值小于10小时的时候如何补零,把空格替换成0。BAT批处理中的字符串截取替换。

一、假设显示的时间是九点多,执行time的时候是 9:59:56,9前面没有0,9前面是有一个空格的。

C:\Users>time
The current time is:  9:59:56.82
Enter the new time:
C:\Users>

二、9:59:56这种显示风格跟我们的常用的不一致,我们希望是09:59:56,9前面是0,下面的代码的就是把空格替换成0.

set t=%time:~0,8%
set  mt=%t: =0%
echo mt = %mt%  

  
set mtime=%time: =0%
echo mtime=%mtime%
set  rtime=%mtime:~0,8%
echo rtime=%rtime%

 三、参考文章

【转】BAT批处理中的字符串处理详解(字符串截取) - 神奇的旋风 - 博客园

猜你喜欢

转载自blog.csdn.net/qq_37858386/article/details/123728456