Time conversion

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
 
M

Morten Wennevik [C# MVP]

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.
 
R

Ronny

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top