![]() |
C - Entwicklung Bibliotheks-Funktionen: Umwandlung von Datum und Zeit Homepage von PS-Trainer - C-Entwicklung - Datum & Zeit - an PS-Trainer |
|
| Date and Time Management | |
| asctime, _wasctime , structure tm | Converts a tm time structure to a character string. |
| ctime, _wctime | Convert a time value to a string and adjust for local time zone settings. |
| localtime , structure tm | Converts a time value and corrects for the local time zone. |
| mktime | Converts the local time to a calendar value. |
| gmtime | Converts a time value to a structure. |
| strftime, wcsftime | Format a time string. |
| asctime, _wasctime Converts a tm time structure to a character string. char *asctime( const struct tm *timeptr ); wchar_t *_wasctime( const struct tm *timeptr );
Remarks The asctime function converts a time stored as a structure to a character string. The timeptr value is usually obtained from a call to gmtime or localtime, which both return a pointer to a tm structure, defined in TIME.H.
The converted character string is also adjusted according to the local time zone settings. See the time, _ftime, and localtime functions for information on configuring the local time and the _tzset function for details about defining the time zone environment and global variables. The string result produced by asctime contains exactly 26 characters and has the form Wed Jan 02 02:03:55 1980\n\0. A 24-hour clock is used. All fields have a constant width. The newline character and the null character occupy the last two positions of the string. asctime uses a single, statically allocated buffer to hold the return string. Each call to this function destroys the result of the previous call. _wasctime is a wide-character version of asctime. _wasctime and asctime behave identically otherwise. Generic-Text Routine Mapping:
Subject: Time Management Routines Keywords: See also ctime, _ftime, gmtime, localtime, time, _tzset |
|||||||||||||||||||||||||||||||||||||||||
| Return Value asctime returns a pointer to the character string result; _wasctime returns a pointer to the wide-character string result. There is no error return value. Parameter
|
|||||||||||||||||||||||||||||||||||||||||
|
Example #include <time.h> struct tm *newtime; void main( void ) newtime = localtime(
&aclock ); /* Convert time to struct */ /* Print local time as a string
*/ |
| ctime, _wctime Convert a time value to a string and adjust for local time zone settings. char *ctime( const time_t *timer ); wchar_t *_wctime( const time_t *timer );
Remarks The ctime function converts a time value stored as a time_t structure into a character string. The timer value is usually obtained from a call to time, which returns the number of seconds elapsed since midnight (00:00:00), January 1, 1970, coordinated universal time (UTC). The string result produced by ctime contains exactly 26 characters and has the form: Wed Jan 02 02:03:55 1980\n\0 A 24-hour clock is used. All fields have a constant width. The newline character ('\n') and the null character ('\0') occupy the last two positions of the string. The converted character string is also adjusted according to the local time zone settings. See the time, _ftime, and localtime functions for information on configuring the local time and the _tzset function for details about defining the time zone environment and global variables. A call to ctime modifies the single statically allocated buffer used by the gmtime and localtime functions. Each call to one of these routines destroys the result of the previous call. ctime shares a static buffer with the asctime function. Thus, a call to ctime destroys the results of any previous call to asctime, localtime, or gmtime. _wctime is a wide-character version of ctime; _wctime returns a pointer to a wide-character string. _wctime and ctime behave identically otherwise. Generic-Text Routine Mappings
Subject: Time Management Routines Keywords: See also asctime, _ftime, gmtime, localtime, time |
|||||||||||||||||||||
| Return Value Each of these functions returns a pointer to the character string result. If time represents a date before midnight, January 1, 1970, UTC, the function returns NULL. Parameter
|
|||||||||||||||||||||
|
Example #include <time.h> void main( void ) time(
<ime ); |
| localtime Converts a time value and corrects for the local time zone. struct tm *localtime( const time_t *timer );
Return Value localtime returns a pointer to the structure result. If the value in timer represents a date before midnight, January 1, 1970, localtime returns NULL. The fields of the structure type tm store the following values, each of which is an int:
Remarks The localtime function converts a time stored as a time_t value and stores the result in a structure of type tm. The long value timer represents the seconds elapsed since midnight (00:00:00), January 1, 1970, coordinated universal time (UTC). This value is usually obtained from the time function. gmtime, mktime, and localtime all use a single statically allocated tm structure for the conversion. Each call to one of these routines destroys the result of the previous call. localtime corrects for the local time zone if the user first sets the global environment variable TZ. When TZ is set, three other environment variables (_timezone, _daylight, and _tzname) are automatically set as well. See _tzset for a description of these variables. TZ is a Microsoft extension and not part of the ANSI standard definition of localtime. Note The target environment should try to determine whether daylight saving time is in effect. Subject: Time Management Routines Keywords: See also asctime, ctime, _ftime, gmtime, time, _tzset |
||||||||||||||||||||||||
Parameter
|
||||||||||||||||||||||||
|
Example #include <stdio.h> void main( void ) time(
&long_time ); /* Get time as long integer. */ if( newtime->tm_hour >
12 ) /* Set up extension. */ printf( "%.19s %s\n",
asctime(
newtime ), am_pm ); |
| mktime Converts the local time to a calendar value. time_t mktime( struct tm *timeptr );
Remarks The mktime function converts the supplied time structure (possibly incomplete) pointed to by timeptr into a fully defined structure with normalized values and then converts it to a time_t calendar time value. For description of tm structure fields, see asctime. The converted time has the same encoding as the values returned by the time function. The original values of the tm_wday and tm_yday components of the timeptr structure are ignored, and the original values of the other components are not restricted to their normal ranges. mktime handles dates in any time zone from midnight, January 1, 1970, to midnight, February 5, 2036. If successful, mktime sets the values of tm_wday and tm_yday as appropriate and sets the other components to represent the specified calendar time, but with their values forced to the normal ranges; the final value of tm_mday is not set until tm_mon and tm_year are determined. When specifying a tm structure time, set the tm_isdst field to 0 to indicate that standard time is in effect, or to a value greater than 0 to indicate that daylight savings time is in effect, or to a value less than zero to have the C run-time library code compute whether standard time or daylight savings time is in effect. (The C run-time library assumes the United States's rules for implementing the calculation of Daylight Saving Time). tm_isdst is a required field. If not set, its value is undefined and the return value from mktime is unpredictable. If timeptr points to a tm structure returned by a previous call to asctime, gmtime, or localtime, the tm_isdst field contains the correct value. Note that gmtime and localtime use a single statically allocated buffer for the conversion. If you supply this buffer to mktime, the previous contents are destroyed. Subject: Time Management Routines Keywords: See also asctime, gmtime, localtime, time |
||||||
| Return Value mktime returns the specified calendar time encoded as a value of type time_t. If timeptr references a date before midnight, January 1, 1970, or if the calendar time cannot be represented, the function returns 1 cast to type time_t. Parameter
|
||||||
| Example /* MKTIME.C: The example takes a number of days * as input and returns the time, the current * date, and the specified number of days. */ #include <time.h> void main( void ) time( &now ); when.tm_mday = when.tm_mday
+ days; How many days
to look ahead: 29 |
| gmtime Converts a time value to a structure. struct tm *gmtime( const time_t *timer );
Remarks The gmtime function breaks down the timer value and stores it in a statically allocated structure of type tm, defined in TIME.H. The value of timer is usually obtained from a call to the time function. Note: The target environment should try to determine whether daylight savings time is in effect. The C run-time library assumes the United States's rules for implementing the calculation of Daylight Saving Time (DST). Subject: Time Management Routines Keywords: See also asctime, ctime, _ftime, localtime, mktime, time |
||||||||||||||||||||
| Return Value gmtime returns a pointer to a structure of type tm. The fields of the returned structure hold the evaluated value of the timer argument in UTC rather than in local time. Each of the structure fields is of type int, as follows:
The gmtime, mktime, and localtime functions use the same single, statically allocated structure to hold their results. Each call to one of these functions destroys the result of any previous call. If timer represents a date before midnight, January 1, 1970, gmtime returns NULL. There is no error return. Parameter
|
||||||||||||||||||||
|
Example #include <time.h> void main( void ) time( <ime ); /* Obtain coordinated universal
time: */ |
| strftime, wcsftime Format a time string. size_t strftime( char *strDest, size_t maxsize, const char *format, const struct tm *timeptr ); size_t wcsftime( wchar_t *strDest, size_t maxsize, const wchar_t *format, const struct tm *timeptr );
Remarks The strftime and wcsftime functions format the tm time value in timeptr according to the supplied format argument and store the result in the buffer strDest. At most, maxsize characters are placed in the string. For a description of the fields in the timeptr structure, see asctime. wcsftime is the wide-character equivalent of strftime; its string-pointer argument points to a wide-character string. These functions behave identically otherwise. Note Prior to this version of Visual C++, the documentation described the format parameter of wcsftime as having the datatype const wchar_t *, but the actual implementation of the format datatype was const char *. In this version, the implementation of the format datatype has been updated to reflect the previous and current documentation, that is: const wchar_t *. Generic-Text Routine Mappings
The format argument consists of one or more codes; as in printf, the formatting codes are preceded by a percent sign (%). Characters that do not begin with % are copied unchanged to strDest. The LC_TIME category of the current locale affects the output formatting of strftime.(For more information on LC_TIME, see setlocale.) The formatting codes for strftime are listed below:
In that case, the meaning of the format code is changed as follows:
Subject: Locale Routines, Time Management Routines, String Manipulation Routines Keywords: See also localeconv, setlocale, strcoll, _stricoll, strxfrm |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Return Value strftime returns the number of characters placed in strDest if the total number of resulting characters, including the terminating null, is not more than maxsize. wcsftime returns the corresponding number of wide characters. Otherwise, the functions return 0, and the contents of strDest is indeterminate. Parameters
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Example #include <time.h> void main() /* Set time zone from TZ environment
variable. If TZ is not set, /* Display operating system-style
date and time. */ /* Get UNIX-style time and
display as number and string. */ /* Display UTC. */ /* Convert to time structure
and adjust for PM if necessary. */ /* Note how pointer addition
is used to skip the first 11 /* Print additional time information.
*/ /* Make time for noon on Christmas,
1993. */ /* Use time structure to build
a customized time string. */ /* Use strftime to build a
customized time string. */ Output Today is Tuesday, day 03 of May in the year 1994. |
| Aktuelle Daten dieser Seite | Letzte Änderung: |
| |