How do you get the time zeroes out?

Asked

Viewed 73 times

1

I am using a Label to receive the time of a video. The time I receive from the video is a double which comes in milliseconds, for example: 1555 = 1,555 sec. When I convert to TimeSpanthe label appears as follows: inserir a descrição da imagem aqui

the code I’m using is:

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

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

2 answers

1

Using this code will "truncate" the value to 3 decimal places, however you may lose the ":"

Cronometro.Text = dt.tostring("N3");

0

Hello, you can use the function substring for that reason.

In this case you would take HH:MM:SS:MS, which would give 11 characters (considering the :), i.e., you would take the characters from position 0 up 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);

Browser other questions tagged

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