wxDateTime formatting under Windows XP

Denis Dowling dpd at alphalink.com.au
Mon Oct 16 03:17:06 PDT 2006


Hi,

When running under Windows XP the default date ordering in the 
wxDateTime::Format() method is always American. This is really annoying 
to non American users and was causing problems to some database access 
code I was working on. When I dug into the code I found that this was 
not really the fault of wxWidgets but rather a fairly poor choice of 
default date formats by Microsoft. It turns out the the default C local 
will always format a short date as MM/DD/YY rather than something sensible.

The fix is to add this magic in your applications OnInit() routine:

bool MyApp::OnInit()
{
#if defined(__WXMSW__)
    setlocale (LC_COLLATE, ".OCP");      // sets the sort order
    setlocale (LC_MONETARY, ".OCP");     // sets the currency formatting 
rules
    setlocale (LC_NUMERIC, ".OCP");      // sets the formatting of numerals
    setlocale (LC_TIME, ".OCP");         // defines the date/time formatting
#endif
....
}

The ".OCP" locale is an internal locale used under Windows to grab all 
of the formating rules from the users setting. See 
http://www.microsoft.com/globaldev/getwr/steps/wrg_lclmdl.mspx for more 
detail.

I thought I had better share this with the list as I am sure I am not 
the only person who has wanted to get sensible date and time formatting 
when using wxWidgets on Windows.

I am using version 2.6.3 of wxWidgets. I am not sure if this problem 
exists in the latest versions of wxWidgets.






More information about the wx-users mailing list