/************************************************************************ * * * Copyright Digital Equipment Corporation 1998. All rights reserved. * * * * Restricted Rights: Use, duplication, or disclosure by the U.S. * * Government is subject to restrictions as set forth in subparagraph * * (c) (1) (ii) of DFARS 252.227-7013, or in FAR 52.227-19, or in FAR * * 52.227-14 Alt. III, as applicable. * * * * This software is proprietary to and embodies the confidential * * technology of Digital Equipment Corporation. Possession, use, or * * copying of this software and media is authorized only pursuant to a * * valid written license from Digital or an authorized sublicensor. * * * ************************************************************************/ /* wcsftime_example.c */ /* Exersize the wcsftime formating routine. */ /* NOTE: the format string is a "L" (or wide character) */ /* string indicationd that this call is NOT in */ /* the XPG4 format, but it is in ISO C format. */ #include #include #include #include #include #include #define NUM_OF_DATES 7 #define BUF_SIZE 256 /* This program will format a number of different dates, once using the */ /* C locale and then using the fr_FR.ISO8859-1 locale. Date and time */ /* formatting is done using wcsftime() */ main() { int count, i; wchar_t buffer[BUF_SIZE]; struct tm *tm_ptr; time_t time_list[NUM_OF_DATES] = {500, 68200000, 694223999, 694224000, 704900000, 705000000, 705900000}; /* Display dates using the C locale */ printf("\nUsing the C locale:\n\n"); setlocale(LC_ALL, "C"); for (i = 0; i < NUM_OF_DATES; i++) { /* Convert to a tm structure */ tm_ptr = localtime(&time_list[i]); /* Format the date and time */ count = wcsftime(buffer, BUF_SIZE, L"Date: %A %d %B %Y%nTime: %T%n%n", tm_ptr); if (count == 0) { perror("wcsftime"); exit(EXIT_FAILURE); } /* Print the result */ printf("%S", buffer); } /* Display dates using the fr_FR.ISO8859-1 locale */ printf("\nUsing the fr_FR.ISO8859-1 locale:\n\n"); setlocale(LC_ALL, "fr_FR.ISO8859-1"); for (i = 0; i < NUM_OF_DATES; i++) { /* Convert to a tm structure */ tm_ptr = localtime(&time_list[i]); /* Format the date and time */ count = wcsftime(buffer, BUF_SIZE, L"Date: %A %d %B %Y%nTime: %T%n%n", tm_ptr); if (count == 0) { perror("wcsftime"); exit(EXIT_FAILURE); } /* Print the result */ printf("%S", buffer); } }