Time conversion

  • Thread starter Thread starter Marc Gravell
  • Start date Start date
M

Marc Gravell

Well, DateTime and TimeSpan both have static Parse methods to convert a
string into a DateTime/TimeSpan (respectively). Give them a go; I can't
check at the moment (installing SP1...).

Marc
 
Ronny said:
I have a text box with a time data represented as 10:35
How can I convert it into a Time data type?

Regards
Ronny

Hi Ronny,

DateTime has a ParseExact static method that allows you to specify any
date/time format in a string.

DateTime dt = DateTime.ParseExact("10:35", "HH:mm", null);

You will end up with todays date and the parsed time.

A description of the various date/time format codes can be found here

[Custom Date and Time Format Strings]
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx

You can also use this when converting a DateTime object to string.
 
I have a text box with a time data represented as 10:35
How can I convert it into a Time data type?

Regards
Ronny
 
Back
Top