Click here to Skip to main content
15,924,581 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello

I am trying to convert String into Time Span and assigning to Time Control.

Using this Code:

C#
string CurrTime =lblPlaybackTime.Content.ToString();   //e.g. lblPlaBackTime.Content="14:02:11:"
                   startTimeCtrl.Value = TimeSpan.Parse(CurrTime.Remove(2, 1).Remove(4, 1).Remove(6, 1));



But Not working.throws exception.


Thanks
Posted
Updated 23-Nov-11 0:20am
v2

Stop removing the colon characters:
C#
TimeSpan ts = TimeSpan.Parse("12:15:06");
Works fine: 12 hours, 15 minutes, and 6 seconds.

[edit]Typo: 16 seconds instead of 6 - OriginalGriff[/edit]
 
Share this answer
 
v2
DateTime start_time = DateTime.Parse("1/9/2011");
DateTime spot_time = DateTime.Parse("5/9/2011");
TimeSpan diff = spot_time.Subtract(start_time);

Hope this may help u ....
 
Share this answer
 

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