Getting time span between two times in C#?

后端 未结 4 593
有刺的猬
有刺的猬 2020-11-30 01:22

I have two textboxes. One for a clock in time and one for clock out. The times will be put in this format:

Hours:Minutes

Lets say I have cl

4条回答
  •  一整个雨季
    2020-11-30 02:21

    Another way ( longer ) In VB.net [ Say 2300 Start and 0700 Finish next day ]

    If tsStart > tsFinish Then

                                ' Take Hours difference and adjust accordingly
                                tsDifference = New TimeSpan((24 - tsStart.Hours) + tsFinish.Hours, 0, 0)
    
                                ' Add Minutes to Difference
                                tsDifference = tsDifference.Add(New TimeSpan(0, Math.Abs(tsStart.Minutes - tsFinish.Minutes), 0))
    
    
                                ' Add Seonds to Difference
                                tsDifference = tsDifference.Add(New TimeSpan(0, 0, Math.Abs(tsStart.Seconds - tsFinish.Seconds)))
    

提交回复
热议问题