English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Tutorial básico de linguagem C

Controle de fluxo de linguagem C

Funções no C

Matrizes no C

Ponteiro no C

String no C

Estrutura de linguagem C

Arquivo de linguagem C

Outros C

Manual de referência do linguagem C

Biblioteca padrão C <time.h>

time.h O cabeçalho define quatro tipos de variáveis, duas macros e várias funções de operações de data e hora.

Variáveis da biblioteca

A seguir estão os tipos de variáveis definidos no cabeçalho time.h:

NumberVariável & Descrição
1size_t
É um tipo de inteiro sem sinal, é sizeof O resultado da palavra-chave.
2clock_t
Este é um tipo adequado para armazenar tempo de processador.
3time_t is
This is suitable for storing calendar time types.
4struct tm
This is a structure used to save time and date.

The definition of the tm structure is as follows:

struct tm {
   int tm_sec;         /* Second, ranging from 0 to 59        */
   int tm_min;         /* Minute, ranging from 0 to 59        */
   int tm_hour;        /* Hour, ranging from 0 to 23        */
   int tm_mday;        /* Day of the month, ranging from 1 to 31    */
   int tm_mon;         /* Month, ranging from 0 to 11        */
   int tm_year;        /* Since 19Years since 00        */
   int tm_wday;        /* Day of the week, ranging from 0 to 6    */
   int tm_yday;        /* Day of the year, ranging from 0 to 365    */
   int tm_isdst;       /* Daylight Saving Time                */
};

Library Macro

The following are the macros defined in the header file time.h:

NumberMacro & Description
1NULL
This macro is the value of a null pointer constant.
2CLOCKS_PER_SEC
This macro represents the number of processor clock cycles per second.

Library Function

The following are the functions defined in the header file time.h:

NumberFunction & Description
1char *asctime(const struct tm *timeptr)
Returns a pointer to a string that represents the date and time of the structure timeptr.
2clock_t clock(void)
Returns the time used by the processor clock since the start of program execution (usually at the beginning of the program).
3char *ctime(const time_t *timer)
Returns a string representing the local time, based on the parameter timer.
4double difftime(time_t time12, time_t time
)1 Returns time2 and time1-The difference in seconds between (time2time
5struct tm *)。 *timer)
The value of the timer is decomposed into a tm structure and represented in Coordinated Universal Time (UTC), also known as Greenwich Mean Time (GMT).
6struct tm *localtime(const time_t *timer)
The value of the timer is decomposed into a tm structure and represented in the local time zone.
7time_t mktime(struct tm *timeptr)
Convert the structure pointed to by timeptr to a time_t value based on the local time zone.
8size_t strftime(char *str, size_t maxsize, const char *format, const struct tm *timeptr)
Formatar a estrutura de tempo representada pelo timeptr com base nas regras de formatação definidas no format, e armazená-la em str.
9time_t time(time_t *timer)
Calcular a data do calendário atual e codificá-la no formato time_t.