Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 331
  • Last Modified:

Get System Date Format

Hi Experts,

Is there a way to get the setting for the short date format from Windows?

I need the dates displayed in my program customized to the region the program is being used in.

For example....mm/dd/yyyy, dd/mm/yy, dd/mm/yyyy, etc...

Or is there a way to send a date/string to Windows and have it return a formatted date?

Please no MFC.

Thanks!

-Me
0
CPOsosky
Asked:
CPOsosky
1 Solution
 
jkrCommented:
You can do that using either 'setlocale()' like

char* pszDateTime = setlocale(LC_TIME, NULL);

or 'GetLocaleInfo()'.

To have Windows format the output automatically using

TCHAR g_szBuf1[MAX_STR];
GetDateFormat(
  LOCALE_USER_DEFAULT,  // the locale for which the formatting is
                        //    being done
  DATE_LONGDATE,        // date format (long, short, ...)
  NULL,                 // the date to be formatted (here current
                        //    system date)
  NULL,                 // style of date format
  g_szBuf1,             // output buffer
  MAX_STR               // size of output buffer
);
MessageBox(NULL, g_szBuf1, TEXT("Long date format"), MB_OK);
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now