Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
This is driving me crazy. I work around time format lately. I get a value from a slider as a double. Then I convert the value into Time because I need to display the value into time format : [00:00:00.00] on a textblock. My problem is that with my code now I am printing the value like this:
00:00:00.0000000000

C#
double sliderValue = slider.Value;  
  TimeSpan Time = TimeSpan.FromHours(sliderValue);         
  this.TimeText.Text = String.Format("0:hh\\:mm", Convert.ToString(Time));


How can I remove those extra ms ?
Posted

C#
this.TimeText.Text = Time.ToString("hh\\:mm\\:ss\\:ff");
 
Share this answer
 
Use TimeSpan.ToString method to format output...
http://msdn.microsoft.com/en-us/library/1ecy8h51(v=vs.110).aspx[^]
 
Share this answer
 
A solution was:

C#
var slider = sender as Slider;
double sliderValue = Math.Round(slider.Value,2);
TimeSpan Time = TimeSpan.FromHours(sliderValue);
this.TimeText.Text = String.Format("{0:hh\\:mm\\:ss}",Convert.ToString(Time));
 
Share this answer
 
Comments
Tomas Takac 4-Dec-14 6:20am    
Are you sure this works? I think Convert.ToString(Time) ruins it completely.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900