Reputation: 3424
The following code (Windows, C++) sets the current locale and retrieves a formatted short date string, formatted according to locale's short date format "%c".
time_t rawtime;
struct tm * timeinfo;
char buffer [80];
time (&rawtime);
timeinfo = localtime (&rawtime);
strftime (buffer,80,"%c",timeinfo);
Say this gives "31/01/2012" for a given date and locale. This corresponds to a date format of "%d/%m/%Y", although "%c" has been specified.
Is there a way i can get the format string itself, i.e. "%d/%m/%Y" for a given locale?
Upvotes: 4
Views: 1109
Reputation: 1155
There is a call in langinfo to do this
as a simple demo
#include <stdio.h>
#include <langinfo.h>
int main()
{
printf("%s\n", nl_langinfo( D_FMT ) );
}
If your C compiler is not POSIX compliant, and I thought Windows was supposed to be, then perhaps the answers at this question would be more of a guide
Upvotes: 2