I'm using .NET framework v 3.5 and i need to parse a string representing a timespan into TimeSpan
object.
The problem is that dot separator is used instead of colon... For example 13.00
, or 22.30
So I'm wondering if I have to replace .
with :
or there is a more clean way to obtain this.
Updated answer:
Unfortunately .NET 3 does not allow custom
TimeSpan
formats to be used, so you are left with doing something manually. I 'd just do the replace as you suggest.Original answer (applies to .NET 4+ only):
Use
TimeSpan.ParseExact
, specifying a custom format string:For .Net 3.5 you may use DateTime.ParseExact and use TimeOfDay property
If the TimeSpan format is Twelve Hour time format like this "9:00 AM", then use TimeSpan.ParseExact method with format string "h:mm tt", like this
Thanks.
try This(It worked for me) :
startdate will be a string like 28/02/2018 and ddlstarttime is in HH format like 13.00
Parse out the
DateTime
and use itsTimeOfDay
property which is aTimeSpan
structure: