Unix/Linux编程-时间和日期

时间和日期

有Unix内核提供的基本时间服务是计算自协调世界时(UTC)公元1970年1月1日00:00:00这一特定时间以来经过的秒数。以数据类型time_t表示。

#include <time.h>

time_t time(time_t *calptr);

返回值:成功返回时间值,出错返回-1


时间值作为函数值返回。如果参数非空,则时间值也存放在由calptr指向的单元内。
localtime和gmtime将日历时间转换成分解的时间,并将这些存放在一个结构体中:

struct tm {

               int tm_sec;         /* seconds */

               int tm_min;         /* minutes */

               int tm_hour;        /* hours */

               int tm_mday;        /* day of the month */

               int tm_mon;         /* month */

               int tm_year;        /* year */

               int tm_wday;        /* day of the week */

               int tm_yday;        /* day in the year */

               int tm_isdst;       /* daylight saving time */

           };

 


#include <time.h>

struct tm * gmtime(const time_t *calptr);

struct tm *locatime(const time_t *calptr);

返回值:指向分解的tm结构的指针;出错返回NULL


localtime将日历时间转换成本地时间,而gmtime则将日历时间转换成调统一时间。

函数mktime以本地时间作为参数,将其变成time_t值。

#include <time.h>

time_t mktime(struct tm *tmptr);

返回值:成功返回日历时间,出错返回-1


strftime_l允许调用着将区域指定为参数,除此之外,strftime和strftime_l函数是相同的。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值