Question

I'm trying to measure some code execution and I need to display in minutes:seconds. Since I noticed the TimeSpan can format more easily, I tried to use:

TimeSpan ts = TimeSpan::FromTicks(complete-commence);
String elapsedTime = TimeSpan::Format("mm", ts.Minutes);

But is not working, despite the method exists in MSDN:

Error   1   error C3149: 'System::String' : cannot use this type here without a top-level '^'
Error   2   error C2039: 'Format' : is not a member of 'System::TimeSpan'
Error   3   error C3861: 'Format': identifier not found

What did I do wrong?

Était-ce utile?

La solution

The syntax is wrong, it should be:

TimeSpan ts = TimeSpan::FromTicks(complete-commence);
String^ elapsedTime = ts->ToString("mm\\:ss"); // "mm\\:ss" is minutes:seconds

Note that this is loading the value from Ticks, not seconds or milliseconds. If your input data is in milliseconds, for example, you'd use:

TimeSpan ts = TimeSpan::FromMilliseconds(complete-commence);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top