Number format string: double in time

I have a double value in seconds and I would like to use a numeric format string to display it as mm: ss or hh: mm: ss. Is it possible? Havent found anything about this on MSDN?

The reason is that we are using Telerik chart which displays our data and since I cannot change the hold format I have to bind the format string to my chart api.

Thanks in advance Johan

0


a source to share


2 answers


You're looking for the TimeSpan class .



+1


a source


Use the following:

var ts = new TimeSpan(0, 0, 0, (int)doubleValueOfSeconds, 0);

      

Of course, you can consider a more accurate rounding of the double value, rather than truncation as in my example.

Take a look at the TimeSpan on MSDN to get the string value, although the simplest current culture should be TimeSpan.ToString()

.



UPDATE to updated question :

You cannot directly format a few seconds before date and time. Formatting is essentially string manipulation and you need to do some math before this formatting happens.

Use my example above, then call TimeSpan.ToString(formatString);

to get the string values ​​for the control.

Assuming you're not just missing something. I personally find Telerik's controls to be complex, but I'm pretty sure they will have inline formatting. Basically, write the code using my example above to create the timezone data, and then use the inline format string to tell the control how to format the timezone for the data series data.

0


a source







All Articles