How to take the zeros out of time?

1

I'm using a Label to receive the time of a video. The time I get from the video is double that comes in milliseconds, for example: 1555 = 1,555 sec. When I convert to TimeSpan the Label appears as follows:

The code I'm using is:

        dt = TimeSpan.FromMilliseconds(Player.input.time);
        Cronometro.Text = dt.ToString();

Those zeros that appear after the numbers should not be there. It was supposed to be 00: 00: 03.431 I use a Windows Form.

    
asked by anonymous 17.06.2016 / 03:35

2 answers

1

If you use this code will "truncate" the value to 3 decimal places, however you can lose the ":"

Cronometro.Text = dt.tostring("N3");
    
17.06.2016 / 03:48
0

Hello, you can use the substring function to do this.

In this case you would get HH: MM: SS: MS, which would give you 11 characters (considering the :), ie you would get the characters from position 0 to position 11.

//cria uma variável string cujo conteúdo vem de dt(sua variável que guarda o     tempo)
string tempo = dt.ToString()
// Obtém 11 caracteres a partir da posição 0 (primeiro caracter)
Cronometro.Text = tempo.Substring(0, 11);
    
18.06.2016 / 17:03