Get time difference between two timespan in vb.net

后端 未结 3 1664
夕颜
夕颜 2020-12-18 00:30

I have two variables :

Dim starttime As TimeSpan
Dim endtime As TimeSpan

My starttime value is : 02:30:00 (I mean 2.30AM)
2.30AM is nex

3条回答
  •  渐次进展
    2020-12-18 01:01

    You need to use a DateTime variable to hold your start time and end time. Like this:

    Dim startTime As New DateTime(2013, 9, 19, 10, 30, 0)     ' 10:30 AM today
    Dim endTime As New DateTime(2013, 9, 20, 2, 0, 0)     ' 2:00 AM tomorrow
    
    Dim duration As TimeSpan = endTime - startTime        'Subtract start time from end time
    
    Console.WriteLine(duration)
    

    Result:

    15:30:00

    UPDATE:

    To convert that result to minutes, you can use the TotalMinutes property of the TimeSpan variable:

    Console.WriteLine(duration.TotalMinutes)
    

    Result:

    930

提交回复
热议问题