时间和日期例程

由unix内核提供的基本时间服务是计算自国际标准时间公元1970年1月1日00:00:00以来经过的秒数。

time函数返回当前时间和日期。

#include <time.h>

time_t time(time_t *calptr);

时间值总是作为函数值返回。如果参数不为空,则时间值也存放在由calptr指向的单元内。


gettimeofday提供了更高的分辨率(最高为微秒级)

int gettimeofday(struct timeval *restrict tp, void *restrict tzp);


localtime和gmtime可将日历时间转换成以年、月、日、时、分、秒、周日表示的时间。

struct tm *gmtime(const time_t *calptr);

struct tm *localtime(const time_t *calptr);

localtime将日历时间转换成本地时间,而gmtime则将日历时间转换成国际标准时间(0时区)。


mktime以本地时间的年、月、日等作为参数,将其转换成time_t值。

time_t mktime(strcut tm *tmptr);


asctime和ctime函数产生26字节的字符串,如Tue Feb 10 18:27:38 2004\n\0

char *asctime(const struct tm *tmptr);

char *ctime(const time_t *calptr);


strftime是非常复杂的类似于printf的时间值函数。

size_t strftime(char *restrict buf, size_t maxsize, const char *restrict format, const struct tm *restrict tmptr);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值