/************************************************************************ * * * 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. * * * ************************************************************************/ /* strftime_example.c */ #include #include #include #include #include #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 strftime(). */ main() { int count, i; char 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 = strftime(buffer, BUF_SIZE, "Date: %A %d %B %Y%nTime: %T%n%n", tm_ptr); if (count == 0) { perror("strftime"); exit(EXIT_FAILURE); } /* Print the result */ printf(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 = strftime(buffer, BUF_SIZE, "Date: %A %d %B %Y%nTime: %T%n%n", tm_ptr); if (count == 0) { perror("strftime"); exit(EXIT_FAILURE); } /* Print the result */ printf(buffer); } }