var todayAt2PM = new DateTime(
DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 14, 0, 0);
Debug.Print("{0:t}", todayAt2PM);
Debug.Print("{0}", todayAt2PM.ToString("t"));
Debug.Print("{0}", todayAt2PM.ToShortTimeString());
When I run this in C#, I get:
14:00
2:00 PM
2:00 PM
CultureInfo.CurrentCulture and CultureInfo.CurrentUICulture are both set to “en-US” on my PC. I haven’t done any customizations to my regional settings; when I go to that part of Control Panel, everything indicates 12-hour time, with AM and PM.
So why does “{0:t}” print using 24-hour time?
I think the problem is with
Debug.Printrather than with thetformat specifier. If you useConsole.WriteLineinstead ofDebug.Print, it gives the expected result.EDIT: just had a look with Reflector…
Debug.Printalways uses the invariant culture, not the current culture, and the time format in that culture is 24-hour