How to decrease TimeSpan time?

2

I need to set a time within TimeSpan , and make it shorten the time. When you get to [00:00:00], for the time. I need to do this format: [00:00:00] - hour, minute, and second.

Below, I put 5 min.

private void timer1_Tick(object sender, EventArgs e)
{
    TimeSpan tp = new TimeSpan(5, 0, 0);
    string horario = "horario do timespan decrementado aqui";
}

It's like the stopwatch, I put a time and when it reaches a limit, for everything. The limit in this case here would be [00:00:00].

    
asked by anonymous 08.02.2018 / 21:48

2 answers

3

I do not really like this solution, but this would be it:

tp = tp - TimeSpan.FromSeconds(1);
    
08.02.2018 / 22:08
1

Note: If you want 5 minutes, the parameter is the second of the TimeSpan constructor.

I suppose you put the range from timer1 to 1000 ms, Your code should look something like this:

TimeSpan tp = new TimeSpan(0, 5, 0);

private void timer1_Tick(object sender, EventArgs e)
{
    tp = tp - TimeSpan.FromSeconds(1);
    string horario = tp.ToString("hh\:mm\:ss");
}

I made an example in SQLFiddle, without computing the range:

link

    
08.02.2018 / 22:23