How to Decrease Timespan Time?

Asked

Viewed 290 times

2

I need to put a schedule inside the TimeSpan, and make it slow down. When it gets to [00:00:00] for the time. Need to do in 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 is as if it were the stopwatch, I put a time and when it reaches a limit, for everything. The limit in this case, here, would be the [00:00:00].

  • Resolves Sergio ?

  • 1

    @Rovannlinhalis yes!

2 answers

3


1

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

I imagine you’ve put the interval on timer1 for 1000 ms, Your code must be 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 interval:

https://dotnetfiddle.net/EXZ4Zf

Browser other questions tagged

You are not signed in. Login or sign up in order to post.