Alex Rivera | Logout

Convert AM/PM time to 24 hours format?

Asked 2011-12-01T07:00:24.497
30

I need to convert 12 hours format time (am/pm) to 24 hours format time, e.g. 01:00 PM to 13:00 using C#. How can I convert it?

Edit
Report

1 Answer

20

You'll want to become familiar with Custom Date and Time Format Strings.

DateTime localTime = DateTime.Now;

// 24 hour format -- use 'H' or 'HH'
string timeString24Hour = localTime.ToString("HH:mm", CultureInfo.CurrentCulture);
answered 2011-12-01T07:05:33.660

Your Answer