如何使用批处理计算两个时间点的时间差?

我想计算例如[00:02:15]与[00:05:08]之间的时间差。在网上搜索了很久,找到了不少内容。但太多数有点复杂,我刚接触批处理,看不太懂。比如这个(http://bbs.bathome.net/thread-4701-1-1.html): :: etime -- 求%1--%2 的时间差,时间跨度在24小时内可调用之;:etime <beginTimeVar> <endTimeVar> <retVar> // code by plp626if "!OS!" neq "%OS%" (echo %0 需要再开启变量延迟后调用&goto:eof)Set/a "%3=(!%2:~,2!-!%1:~,2!)*360000+(1!%2:~3,2!-1!%1:~3,2!)*6000+1!%2:~-5,2!!%2:~-2!-1!%1:~-5,2!!%1:~-2!,%3+=-8640000*(%3>>31)"&goto:eof 我自己尝试了一下call :etime 00:02:15 00:05:08提示“运算符不存在” 请问该如何写才正确呢?得到的结果我希望是hh:mm:ss的格式(毫秒不计算也没关系)谢谢大家
2026年09月25日 22:18
有3个网友回答
网友(1):

获取里面MyEvent这个事件的反馈值Imports System
Imports System.Reflection
Imports System.Security
Imports Microsoft.VisualBasic

' Compile this sample using the following command line:
' vbc type_getevent.vb /r:"System.Windows.Forms.dll" /r:"System.dll"

Class MyEventExample
    Public Shared Sub Main()
        Try
            Dim myType As Type = GetType(System.Windows.Forms.Button)
            Dim myEvent As EventInfo = myType.GetEvent("Click")
            If Not (myEvent Is Nothing) Then
                Console.WriteLine(ControlChars.Cr + "Looking for the Click event in the Button class.")
                Console.WriteLine(ControlChars.Cr + myEvent.ToString())
            Else
                Console.WriteLine("The Click event is not available with the Button class.")
            End If
        Catch e As SecurityException
            Console.WriteLine("An exception occurred.")
            Console.WriteLine("Message :" + e.Message)
        Catch e As ArgumentNullException
            Console.WriteLine("An exception occurred.")
            Console.WriteLine("Message :" + e.Message)
        Catch e As Exception
            Console.WriteLine("The following exception was raised : {0}", e.Message)
        End Try
    End Sub 'Main
End Class 'MyEventExample

网友(2):

好个骨瘦如柴版! 可要在此基础上要再转为时分秒可就胖了

网友(3):

Call :etime 6:25:40.41 6:25:44.73 return
Echo %return%
Pause
:etime    
rem 所测试任务的执行时间不超过1天 // 骨瘦如柴版  
setlocal&set be=%~1:%~2&set cc=(%%d-%%a)*360000+(1%%e-1%%b)*6000+1%%f-1%%c&set dy=-8640000 
for /f "delims=: tokens=1-6" %%a in ("%be:.=%")do endlocal&set/a %3=%cc%,%3+=%dy%*("%3>>31")&exit/b

用的是14楼的代码.