Get System Date Format

Posted on 2004-11-04
Last Modified: 2010-04-01
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, 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.


Question by:CPOsosky
    1 Comment
    LVL 86

    Accepted Solution

    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];
      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);

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

      Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
    Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
    The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
    The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now