|
VMS Help CRTL, wcsftime, Example *Conan The Librarian |
/* Exercise the wcsftime formatting routine. */
/* NOTE: the format string is an "L" (or wide character) */
/* string indicating that this call is NOT in */
/* the XPG4 format, but rather in ISO C format. */
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <wchar.h>
#include <locale.h>
#include <errno.h>
#define NUM_OF_DATES 7
#define BUF_SIZE 256
/* This program formats 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);
}
}
Running the example program produces the following result:
Using the C locale:
Date: Thursday 01 January 1970
Time: 00:08:20
Date: Tuesday 29 February 1972
Time: 08:26:40
Date: Tuesday 31 December 1991
Time: 23:59:59
Date: Wednesday 01 January 1992
Time: 00:00:00
Date: Sunday 03 May 1992
Time: 13:33:20
Date: Monday 04 May 1992
Time: 17:20:00
Date: Friday 15 May 1992
Time: 03:20:00
Using the fr_FR.ISO8859-1 locale:
Date: jeudi 01 janvier 1970
Time: 00:08:20
Date: mardi 29 février 1972
Time: 08:26:40
Date: mardi 31 décembre 1991
Time: 23:59:59
Date: mercredi 01 janvier 1992
Time: 00:00:00
Date: dimanche 03 mai 1992
Time: 13:33:20
Date: lundi 04 mai 1992
Time: 17:20:00
Date: vendredi 15 mai 1992
Time: 03:20:00
|
|