C /C++标准库 - <ctime> (time.h)

1. time.h概述

定义了两个宏,声明了四种类型和几个操作时间的函数。很多函数处理都表示当前日期(公历)和时间。有些函数处理本地时间(某个特定时区的时间)和夏令时(是确定本地时间算法的临时替代)。

2. 定义

2.1 types

序号标签说明
1clock_t表示时间的算数类型,CPU时钟计时单元,由clock()返回
2size_t无符号整形,可表示任何对象的bytes数
3time_t时间类型,由time()返回,表示的时间(日历时间)是从一个时间点(1970年1月1日0时0分0秒)到此时的秒数
4struct tmStructure containing a calendar date and time broken down into its components.(tm结构的这种时间表示为分解时间)

2.2 Macro constants

序号标签说明
1NULL空指针
2CLOCKS_PER_SEC是clock返回的每秒钟有多少个时钟计时单元,用于将clock()函数的结果转化为以秒为单位的量,但是这个量的具体值是与操作系统相关的

2.3 Time manipulation(操作)

序号标签原型说明
1clockclock_t clock (void);函数返回从“开启这个程序进程”到“程序中调用clock()函数”时之间的CPU时钟计时单元(clock tick)数,若挂钟时间不可取,则返回-1。如果要以秒为单位计算,只需把函数clock()的返回值除以宏CLOCKS_PER_SEC即可
2difftimedouble difftime (time_t end, time_t beginning);return the result of (end-beginning) in seconds as a floating-point value of type double
3mktimetime_t mktime (struct tm * timeptr);用来将参数timeptr所指的tm结构数据转换成从公元1970年1月1日0时0分0 秒算起至今的本地时间所经过的秒数
4timetime_t time (time_t* timer);获得日历时间(Calendar Time

2.4 Conversion

序号标签原型说明
1asctimechar* asctime (const struct tm * timeptr);Convert tm structure to string,format:Www Mmm dd hh:mm:ss yyyy
2ctimechar* ctime (const time_t * timer);Convert time_t value to string,format:Www Mmm dd hh:mm:ss yyyy, equivalent to: asctime(localtime(timer))
3gmtimestruct tm * gmtime (const time_t * timer);Convert time_t to tm as UTC time
4localtimestruct tm * localtime (const time_t * timer);Convert time_t to tm as local time
5strftimesize_t strftime (char* ptr, size_t maxsize, const char* format,const struct tm* timeptr );strftime() 函数根据区域设置格式化本地时间/日期

3. 参考文献

  1. http://blog.csdn.net/xbaer/article/details/6422326
  2. http://www.cplusplus.com/reference/ctime/
  3. 《C标准库》,P.J. Plauger 著
  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值