I am porting some legacy code from windows to Linux (Ubuntu Karmic to be precise).
I have come across a Win32 function GetDateFormat().
The statements I need to port over are called like this:
GetDateFormat(LOCALE_USER_DEFAULT, 0, &datetime, "MMMM", 'January', 31);
OR
GetDateFormat(LOCALE_USER_DEFAULT, 0, &datetime, "MMMM", 'May', 30);
Where datetime is a SYSTEMTIME struct.
Does anyone know where I can get the code for the function – or failing that, tips on how to “roll my own” equivalent function?
The Linux equivalent (actually, plain ANSI C) to a call to
GetDateFormatlike this:is:
(where
datetimeis now astruct tmrather than aSYSTEMTIME)You may not need to worry about setting the locale each time and setting it back – if you are happy for all of your date/time formatting to be done in the user default locale (which is usual), then you can just call
setlocale(LC_TIME, "");once at program startup and be done with it.Note however that the values your code is passing to
GetDateFormatin thelpDateStrandcchDateparameters (second-last and last respectively) do not make sense.'January'is a character constant, when it should be a pointer to a buffer whereGetDateFormatwill place its result.