Стандарт языка Си С99 TC (1113411), страница 63
Текст из файла (страница 63)
The original values of the tm_wdayand tm_yday components of the structure are ignored, and the original values of theother components are not restricted to the ranges indicated above.276) On successfulcompletion, the values of the tm_wday and tm_yday components of the structure areset appropriately, and the other components are set to represent the specified calendartime, but with their values forced to the ranges indicated above; the final value oftm_mday is not set until tm_mon and tm_year are determined.Returns3The mktime function returns the specified calendar time encoded as a value of typetime_t.
If the calendar time cannot be represented, the function returns the value(time_t)(-1).4EXAMPLEWhat day of the week is July 4, 2001?#include <stdio.h>#include <time.h>static const char *const wday[] = {"Sunday", "Monday", "Tuesday", "Wednesday","Thursday", "Friday", "Saturday", "-unknown-"};struct tm time_str;/* ... */276) Thus, a positive or zero value for tm_isdst causes the mktime function to presume initially thatDaylight Saving Time, respectively, is or is not in effect for the specified time.
A negative valuecauses it to attempt to determine whether Daylight Saving Time is in effect for the specified time.340Library§7.23.2.3WG14/N1256Committee Draft — Septermber 7, 2007ISO/IEC 9899:TC3time_str.tm_year= 2001 - 1900;time_str.tm_mon= 7 - 1;time_str.tm_mday= 4;time_str.tm_hour= 0;time_str.tm_min= 0;time_str.tm_sec= 1;time_str.tm_isdst = -1;if (mktime(&time_str) == (time_t)(-1))time_str.tm_wday = 7;printf("%s\n", wday[time_str.tm_wday]);7.23.2.4 The time functionSynopsis1#include <time.h>time_t time(time_t *timer);Description2The time function determines the current calendar time.
The encoding of the value isunspecified.Returns3The time function returns the implementation’s best approximation to the currentcalendar time. The value (time_t)(-1) is returned if the calendar time is notavailable. If timer is not a null pointer, the return value is also assigned to the object itpoints to.7.23.3 Time conversion functions1Except for the strftime function, these functions each return a pointer to one of twotypes of static objects: a broken-down time structure or an array of char.
Execution ofany of the functions that return a pointer to one of these object types may overwrite theinformation in any object of the same type pointed to by the value returned from anyprevious call to any of them. The implementation shall behave as if no other libraryfunctions call these functions.7.23.3.1 The asctime functionSynopsis1#include <time.h>char *asctime(const struct tm *timeptr);Description2The asctime function converts the broken-down time in the structure pointed to bytimeptr into a string in the formSun Sep 16 01:03:52 1973\n\0§7.23.3.1Library341ISO/IEC 9899:TC3Committee Draft — Septermber 7, 2007WG14/N1256using the equivalent of the following algorithm.char *asctime(const struct tm *timeptr){static const char wday_name[7][3] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};static const char mon_name[12][3] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun","Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};static char result[26];sprintf(result, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n",wday_name[timeptr->tm_wday],mon_name[timeptr->tm_mon],timeptr->tm_mday, timeptr->tm_hour,timeptr->tm_min, timeptr->tm_sec,1900 + timeptr->tm_year);return result;}Returns3The asctime function returns a pointer to the string.7.23.3.2 The ctime functionSynopsis1#include <time.h>char *ctime(const time_t *timer);Description2The ctime function converts the calendar time pointed to by timer to local time in theform of a string.
It is equivalent toasctime(localtime(timer))Returns3The ctime function returns the pointer returned by the asctime function with thatbroken-down time as argument.Forward references: the localtime function (7.23.3.4).342Library§7.23.3.2WG14/N1256Committee Draft — Septermber 7, 2007ISO/IEC 9899:TC37.23.3.3 The gmtime functionSynopsis1#include <time.h>struct tm *gmtime(const time_t *timer);Description2The gmtime function converts the calendar time pointed to by timer into a brokendown time, expressed as UTC.Returns3The gmtime function returns a pointer to the broken-down time, or a null pointer if thespecified time cannot be converted to UTC.7.23.3.4 The localtime functionSynopsis1#include <time.h>struct tm *localtime(const time_t *timer);Description2The localtime function converts the calendar time pointed to by timer into abroken-down time, expressed as local time.Returns3The localtime function returns a pointer to the broken-down time, or a null pointer ifthe specified time cannot be converted to local time.7.23.3.5 The strftime functionSynopsis1#include <time.h>size_t strftime(char * restrict s,size_t maxsize,const char * restrict format,const struct tm * restrict timeptr);Description2The strftime function places characters into the array pointed to by s as controlled bythe string pointed to by format.
The format shall be a multibyte character sequence,beginning and ending in its initial shift state. The format string consists of zero ormore conversion specifiers and ordinary multibyte characters. A conversion specifierconsists of a % character, possibly followed by an E or O modifier character (describedbelow), followed by a character that determines the behavior of the conversion specifier.All ordinary multibyte characters (including the terminating null character) are copied§7.23.3.5Library343ISO/IEC 9899:TC3Committee Draft — Septermber 7, 2007WG14/N1256unchanged into the array. If copying takes place between objects that overlap, thebehavior is undefined.
No more than maxsize characters are placed into the array.3Each conversion specifier is replaced by appropriate characters as described in thefollowing list. The appropriate characters are determined using the LC_TIME categoryof the current locale and by the values of zero or more members of the broken-down timestructure pointed to by timeptr, as specified in brackets in the description. If any ofthe specified values is outside the normal range, the characters stored are unspecified.%a%A%b%B%c%C%d%D%e%F%g%G%h%H%I%j%m%M%n%p%r%R%S%t%T344is replaced by the locale’s abbreviated weekday name. [tm_wday]is replaced by the locale’s full weekday name.
[tm_wday]is replaced by the locale’s abbreviated month name. [tm_mon]is replaced by the locale’s full month name. [tm_mon]is replaced by the locale’s appropriate date and time representation. [all specifiedin 7.23.1]is replaced by the year divided by 100 and truncated to an integer, as a decimalnumber (00−99). [tm_year]is replaced by the day of the month as a decimal number (01−31). [tm_mday]is equivalent to ‘‘%m/%d/%y’’. [tm_mon, tm_mday, tm_year]is replaced by the day of the month as a decimal number (1−31); a single digit ispreceded by a space. [tm_mday]is equivalent to ‘‘%Y−%m−%d’’ (the ISO 8601 date format).
[tm_year, tm_mon,tm_mday]is replaced by the last 2 digits of the week-based year (see below) as a decimalnumber (00−99). [tm_year, tm_wday, tm_yday]is replaced by the week-based year (see below) as a decimal number (e.g., 1997).[tm_year, tm_wday, tm_yday]is equivalent to ‘‘%b’’. [tm_mon]is replaced by the hour (24-hour clock) as a decimal number (00−23).
[tm_hour]is replaced by the hour (12-hour clock) as a decimal number (01−12). [tm_hour]is replaced by the day of the year as a decimal number (001−366). [tm_yday]is replaced by the month as a decimal number (01−12). [tm_mon]is replaced by the minute as a decimal number (00−59). [tm_min]is replaced by a new-line character.is replaced by the locale’s equivalent of the AM/PM designations associated with a12-hour clock. [tm_hour]is replaced by the locale’s 12-hour clock time. [tm_hour, tm_min, tm_sec]is equivalent to ‘‘%H:%M’’.
[tm_hour, tm_min]is replaced by the second as a decimal number (00−60). [tm_sec]is replaced by a horizontal-tab character.is equivalent to ‘‘%H:%M:%S’’ (the ISO 8601 time format). [tm_hour, tm_min,tm_sec]Library§7.23.3.5WG14/N1256%u%U%V%w%W%x%X%y%Y%z%Z%%4Committee Draft — Septermber 7, 2007ISO/IEC 9899:TC3is replaced by the ISO 8601 weekday as a decimal number (1−7), where Mondayis 1. [tm_wday]is replaced by the week number of the year (the first Sunday as the first day of week1) as a decimal number (00−53). [tm_year, tm_wday, tm_yday]is replaced by the ISO 8601 week number (see below) as a decimal number(01−53). [tm_year, tm_wday, tm_yday]is replaced by the weekday as a decimal number (0−6), where Sunday is 0.[tm_wday]is replaced by the week number of the year (the first Monday as the first day ofweek 1) as a decimal number (00−53).
[tm_year, tm_wday, tm_yday]is replaced by the locale’s appropriate date representation. [all specified in 7.23.1]is replaced by the locale’s appropriate time representation. [all specified in 7.23.1]is replaced by the last 2 digits of the year as a decimal number (00−99).[tm_year]is replaced by the year as a decimal number (e.g., 1997). [tm_year]is replaced by the offset from UTC in the ISO 8601 format ‘‘−0430’’ (meaning 4hours 30 minutes behind UTC, west of Greenwich), or by no characters if no timezone is determinable.
[tm_isdst]is replaced by the locale’s time zone name or abbreviation, or by no characters if notime zone is determinable. [tm_isdst]is replaced by %.Some conversion specifiers can be modified by the inclusion of an E or O modifiercharacter to indicate an alternative format or specification.