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 p.m.
2:00 PM
CultureInfo.CurrentCultureand CultureInfo.CurrentUICultureboth are set to "en-US" on my PC. I did not make any settings in my regional settings; when I go to that part of the control panel, everything indicates a 12-hour time with AM and PM.
So why does "{0: t}" print using 24-hour time?
source
share