首页 > 其他 > 详细

time函数

时间:2015-12-08 23:42:10      阅读:239      评论:0      收藏:0      [点我收藏+]

time函数

  • time

#include<time.h>

time_t time(time_t *t);

time() returns the time as the number of secs since 1970-01-01 00:00:00 +0000(UTC)

假如参数t不是NULL,返回值(秒数)(日历时间)也存储在t中。

失败返回-1.

  • ctime

#include <time.h>

char *ctime(const time_t *time);

将秒数转化为具体日期(ASCII),长度固定26字节。

the time is 1449579811
the time ascii is Tue Dec  8 21:03:31 2015

等价:asctime(localtime(t));

  • broken-down time

Broken-down time is stored in the structure tm whichi is deiined in time.h as follows:

struct tm {
    int tm_sec;
    int tm_min;
    int tm_hour;
    int tm_mday;
    int tm_mon;
    int tm_year;
    int tm_wday;
    int tm_yday;
    int tm_isdst;
};

tm_year指的是自1900年以来的年数。

  • asctime
char *asctime(const struct tm *tm);

将分离时间装换为字符串时间。

  • localtime
struct tm *localtime(const time_t *timep);

将秒数装换为分离时间。

    • gmtime
struct tm *gmtime(const time_t *timep);

  • mktime
time_t mktime(struct tm *tm);

将分离时间转换为秒数。

    • difftime
double difftime(time_t time1, time_t time0);

The difftime() function returns the number of seconds elapsed between time time1 and time time0, represented as a double. Each of the times is specified in calendar time, which means its value is a measurement (in seconds) relative to the Epoch, 1970-01-01 00:00:00 +0000 (UTC).

  • clock

clock_t clock(void);

DESCRIPTION

   The  clock()  function returns an approximation of processor time used
   by the program.

RETURN VALUE

   The value returned is the CPU time used so far as a  clock_t;  to  get
   the  number of seconds used, divide by CLOCKS_PER_SEC.  If the proces‐
   sor time used is not available or its value cannot be represented, the
   function returns the value (clock_t) -1.

time函数

原文:http://www.cnblogs.com/embedded-linux/p/5031179.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!