1

I'm trying to format dates and times exactly as specified by the user on the "Region and Language" page of the Windows Control Panel. This works semi-automatically for most selections the user makes as long as I use the general formatting strings, like "g" for general short date/time.

But I've encountered at least one exception. If I select Format: "English (United States)" and Short time: "hh:mm tt", then the formatting ignores the "hh" part and instead uses "h:mm tt", i.e., no leading zero for a single-digit hour.

 // Just testing - to be removed
 string s1 = CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern;
 string s2 = CultureInfo.CurrentUICulture.DateTimeFormat.ShortTimePattern;

Adding the above code to my program confirms that .Net is using "h:mm tt" instead of "hh:mm tt" as specified on the Control Panel page.

Is there something I can do to get it to use the specified setting, or to determine the setting myself and then explicitly get the formatting to use "hh:mm tt"?

RenniePet
  • 11,420
  • 7
  • 80
  • 106
  • 1
    This is a known issue with .NET versions prior to 4.0. See http://social.msdn.microsoft.com/Forums/en/netfxbcl/thread/70251d33-5c12-42a0-92f1-98ad4257ad65. Possible workaround at http://stackoverflow.com/q/1292246/56778 – Jim Mischel Aug 28 '12 at 18:51

0 Answers0