Q:

How to convert time format?

My Windows date format is Month/Date/Year. If I want set StartTime with format "yyyy/MM/dd HH:mm:ss", How can I do that. I try the following code.
DateTime StartTime = DateTime.ParseExact("2011/01/04 09:30:00", "yyyy/MM/dd HH:mm:ss", null);

But StartTime come out with 1/4/2011  9:30:00 AM.
                          (month/date/year hh:mm:ss)

A:

You're parsing the time correctly, but displaying it with the default format.  Try StartTime.ToString("yyyy/MM/dd HH:mm:ss")

A:

This code works correctly, and you have a strong-typed DateTime object now. 
If you wish to then output it in the format you have above, then you call ToString() with the format in your second argument. 

A:

It is using your format to parse the date correctly, but it is displaying it by default.  To display it in the format you created it in you will either need to use String.Format or you can even use 'ToString()' with a pattern.

