日期与时间函数 time.h
文章目录
C语言中使用时间和日期函数时,需要添加<time.h>头文件,clock_t和time_t是两个表示时间的算数类型,struct tm用于保存日历时间的各个组成部分。
一、clock_t和time_t的定义
clock_t定义:
#ifndef __CLOCK_T_DEFINED
#define __CLOCK_T_DEFINED // 避免重复定义 clock_t
typedef long clock_t; //clock_t是一个长整形数
#endif
time_t定义:
#ifndef __TIME_T
#define __TIME_T //避免重复定义 time_t
typedef long time_t; //时间值time_t 是一个长整型
#endif
二、struct tm结构体
1.结构体
struct tm
{
int tm_sec;