Convert Difference between 2 times into Milliseconds?

后端 未结 11 2166
梦毁少年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:42

    To answer the title-question:

    DateTime d1 = ...;
    DateTime d2 = ...;
    TimeSpan diff = d2 - d1;
    
    int millisceonds = (int) diff.TotalMilliseconds;
    

    You can use this to set a Timer:

    timer1.interval = millisceonds;
    timer1.Enabled = true;
    

    Don't forget to disable the timer when handling the tick.

    But if you want an event at 12:03, just substitute DateTime.Now for d1.

    But it is not clear what the exact function of textBox1 and textBox2 are.

提交回复
热议问题