C++编程->time.h文件解析

    由于电脑在跑代码,10个小时的空闲,就看库源码消遣吧。

    先挑出一个重要的结构体:

#ifndef _TM_DEFINED struct tm {         int tm_sec;     /* seconds after the minute - [0,59] */         int tm_min;     /* minutes after the hour - [0,59] */         int tm_hour;    /* hours since midnight - [0,23] */         int tm_mday;    /* day of the month - [1,31] */         int tm_mon;     /* months since January - [0,11] */         int tm_year;    /* years since 1900 */         int tm_wday;    /* days since Sunday - [0,6] */         int tm_yday;    /* days since January 1 - [0,365] */         int tm_isdst;   /* daylight savings time flag */         }; #define _TM_DEFINED #endif

这个也就是我们经常要用的一个数据块。

/* Clock ticks macro - ANSI version */  #define CLOCKS_PER_SEC  1000
常用的一个参数,用作毫秒转秒用。

#ifndef _TIME_T_DEFINED #ifdef _USE_32BIT_TIME_T typedef __time32_t time_t;      /* time value */ #else typedef __time64_t time_t;      /* time value */ #endif #define _TIME_T_DEFINED         /* avoid multiple def's of time_t */ #endif
得到从标准计时点(一般是1970年1月1日午夜)到当前时间的秒数。

#ifndef _CLOCK_T_DEFINED typedef long clock_t; #define _CLOCK_T_DEFINED #endif
得到从进程启动到此次函数调用的累计的时钟滴答数。


_Check_return_ _CRT_INSECURE_DEPRECATE(asctime_s) _CRTIMP char * __cdecl asctime(_In_ const struct tm * _Tm); #if __STDC_WANT_SECURE_LIB__ _Check_return_wat_ _CRTIMP errno_t __cdecl asctime_s(_Out_writes_(_SizeInBytes) _Post_readable_size_(26) char *_Buf, _In_ size_t _SizeInBytes, _In_ const struct tm * _Tm); #endif __DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(errno_t, asctime_s, _Post_readable_size_(26) char, _Buffer, _In_ const struct tm *, _Time) 
把分解时间tm输出到字符串,结果的格式为"Www Mmm dd hh:mm:ss yyyy",即“周几 月份数 日数 小时数:分钟数:秒钟数 年份数”。函数返回的字符串为静态分配,长度不大于26,与ctime函数共用。函数的每次调用将覆盖该字符串内容。

_CRT_INSECURE_DEPRECATE(_ctime32_s) _CRTIMP char * __cdecl _ctime32(_In_ const __time32_t * _Time); _CRTIMP errno_t __cdecl _ctime32_s(_Out_writes_(_SizeInBytes) _Post_readable_size_(26) char *_Buf, _In_ size_t _SizeInBytes, _In_ const __time32_t *_Time); __DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(errno_t, _ctime32_s, _Post_readable_size_(26) char, _Buffer, _In_ const __time32_t *, _Time) 
把日历时间time_t timer输出到字符串,输出格式与asctime函数一样

_CRTIMP size_t __cdecl strftime(_Out_writes_z_(_SizeInBytes) char * _Buf, _In_ size_t _SizeInBytes, _In_z_ _Printf_format_string_ const char * _Format, _In_ const struct tm * _Tm); _CRTIMP size_t __cdecl _strftime_l(_Pre_notnull_ _Post_z_ char *_Buf, _In_ size_t _Max_size, _In_z_ _Printf_format_string_ const char * _Format, _In_ const struct tm *_Tm, _In_opt_ _locale_t _Locale); 
把分解时间tm转换为自定义格式的字符串,类似于常见的字符串格式输出函数sprintf

_CRTIMP double __cdecl _difftime32(_In_ __time32_t _Time1, _In_ __time32_t _Time2); 
比较两个日历时间之差。







發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章