Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regional Date Formats

Status
Not open for further replies.

csi95

Programmer
Joined
Feb 3, 2004
Messages
2
Location
US
Forgive me if this is an obvious question, but I've done hours of searching, and I can't figure this out.

VC++ 6 / Win32 platforms

I'm trying to use strftime with the %x option to give me a date in the format specified in the users Control Panel. Though I live in the US, for example, I may have told windows that I want to see dates as dd/mm/yyyy instead of mm/dd/yyyy.

It seems that no matter what I change -- local, format, etc., I get mm/dd/yy.

This is the code:

#include "stdafx.h"
#include <time.h>
#include <ctime>


int main(int argc, char* argv[])
{
time_t oTime;
tm* oDate;
char sThis[25];

time(&oTime);
oDate = localtime(&oTime);

strftime(sThis, 25, &quot;%x&quot;, oDate);

printf(sThis);
return 0;
}


Any ideas?

Is there a Windows API procedure that will accomplish this for me? Any help would be much appreciated.

Bryan
 
Call setlocale() with LC_TIME before using strftime():
Example :

char *pLocale = setlocale(LC_TIME, &quot;German&quot;);
if (pLocale)
{
// locale to German successfuly set
strftime();
//
}
See also _tzset() function for timezone environment variables.
-obislavu-
 
obislavu -- thanks for the post. That's part of what I need. Now the question is, how do I know what locale the persons computer is set to?

In the Control Panel, a user can set their region, and also set any date, time and currency formating they like. My question is, how do I format the date based on their preferences?

There must be some Widows API call to do this, but I just haven't come across it yet.

Any ideas?

- Bryan
 
Use setlocale with NULL like here:
setlocale( LC_TIME, NULL );
and it returns the following string
LC_TIME=English_USA.1252
but to get more involved on that see the National Language Support Functions and use EnumDateFormat()
to get the date format.
See also
GetSystemDefaultLCID()
GetLocaleInfo()
GetThreadLocale()
SetThreadLocale()
...///
- obislavu-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top