1

I'm using the following code to set the format of the Time Picker control (with the Win32 class name SysDateTimePick32) to display time in US English format only:

LCID lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT));
TCHAR buffFmt[200] = {0};
GetLocaleInfo(lcid, LOCALE_STIMEFORMAT, buffFmt, SIZEOF(buffFmt));

TRACE(buffFmt);    //"h:mm:ss tt"

::SendMessage(m_hWnd, DTM_SETFORMAT, 0, (LPARAM)buffFmt);

When I run it on my Windows 7 set up for US English user account the control looks good like this:

enter image description here

But if I run it on a Windows 7 with the user account set up for a German format:

enter image description here

the control looks as such (AM/PM part is missing):

enter image description here

Note that in both cases the format string is "h:mm:ss tt", which according to this page means that tt should stand for AM/PM part.

Any idea how to fix this?

c00000fd
  • 20,994
  • 29
  • 177
  • 400

1 Answers1

2

From the Region and Language control panel dialog, click the "Additional settings" button and then the Time tab. What is set for AM symbol and PM symbol?

On my Windows 7 machine, with the Format set to German, these are both empty strings. The datetime control gets the strings to display from the user's current locale, so even if you force it to display AM/PM in the format string it will not actually have anything to display for this part.

Jonathan Potter
  • 36,172
  • 4
  • 64
  • 79
  • Yes, you're right. They are set as empty strings. Damn! So how can one make the time picker to display time format independent of the Windows user account selection? PS. I'm not talking about US English format. Just in general. Say, I want it to display time in Chinese format on a German user account. – c00000fd Jun 08 '13 at 22:50
  • 1
    Maybe by using callbacks - if you supply X in the format string the control will send you DTN_NOTIFY messages. – Jonathan Potter Jun 08 '13 at 22:52
  • Can I provide my own AM/PM text for the time picker control (apart from changing it system-wide)? – c00000fd Jun 08 '13 at 22:54
  • Sorry, see comment above - replying from a phone is not that easy :) – Jonathan Potter Jun 08 '13 at 22:56
  • Haha. Sorry. Just curious, what smartphone are you using? – c00000fd Jun 08 '13 at 22:59
  • Nexus! How about Lumia for a Windows developer :) I'm on iPhone 5, so can't complain either... – c00000fd Jun 08 '13 at 23:38
  • Back to the original subject. Here's the link that explains how to do custom format: http://msdn.microsoft.com/en-us/library/1887cywc%28v=vs.71%29.aspx – c00000fd Jun 09 '13 at 07:16