Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

change format of C++/CLI stopwatch from System::Diagnostics windows form CLR

private: System::Void button3_Click(System::Object^  sender, System::EventArgs^  e) { 

this->label3->Text = stopWatch.Elapsed.ToString();} 

I need help for changing the format of my stopWatch, how can i put a format like "HH:mm:ss" please ?
because doing this just show the default format that shows too much numbers

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Stopwatch.Elapsed is of type TimeSpan.

This type supports various formats when converting to string.
You can see all the info here: Standard TimeSpan format strings, Custom TimeSpan format strings.

In your case I think the following custom format string will work:

System::String ^ text = stopWatch->Elapsed.ToString("hh\\:mm\\:ss");
this->label3->Text = text;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading