Examples

The following example uses the wcsftime subroutine to format time into a wide character string:

Often begins with a definition, answering the question, "What is this?"

#include <stdio.h>
#include <langinfo.h>
#include <locale.h>
#include <time.h>
 
main()
{
        wchar_t timebuf[BUFSIZE];
        time_t clock = time( (time_t*) NULL);
        struct tim *tmptr = localetime(&clock);
 
        (void)setlocale(LC_ALL, "");
 
        wcsftime(
                timebuf,       /* Time string output buffer */
                BUFSIZ,        /*Maximum size of output string */
                nl_langinfo(D_T_FMT),      /* Date/time format */
                tmptr          /* Pointer to tm structure */
        );
 
        printf("%S\n", timebuf);
}

The following example uses the strptime subroutine to convert a formatted time string to internal format:

#include <langinfo.h>
#include <locale.h>
#include <time.h>
 
main(int argc, char **argv)
{
        struct tm tm;
 
        (void)setlocale(LC_ALL, "");
 
        if (argc != 2) {
                ...                /* Error handling */
        }
        if (strptime(
                argv[1],           /* Formatted time string */
                nl_langinfo(D_T_FMT),      /* Date/time format */
                &tm                /* Address of tm structure */
        ) == NULL) {
                ...                /* Error handling */
        }
        else {
                ...               /* Other Processing */
        }
}