Convert Difference between 2 times into Milliseconds?

后端 未结 11 2186
梦毁少年i
梦毁少年i 2020-12-06 09:11

I have two masked TextBox controls and was wondering how I\'d go about getting the time in each one and then converting the difference into milliseconds. Like, say in tb1 I

11条回答
  •  误落风尘
    2020-12-06 09:45

    You have to convert textbox's values to DateTime (t1,t2), then:

    DateTime t1,t2;
    t1 = DateTime.Parse(textbox1.Text);
    t2 = DateTime.Parse(textbox2.Text);
    int diff = ((TimeSpan)(t2 - t1)).TotalMilliseconds;
    

    Or use DateTime.TryParse(textbox1, out t1); Error handling is up to you.

提交回复
热议问题