linux-time类函数

主要的时间类型:

 1. time_t : long 

 2. struct tm{

    int tm_sec;         /* seconds             0 - 59*/
    int tm_min;         /* minutes             0 - 59*/
    int tm_hour;        /* hours               0 - 23*/
    int tm_mday;        /* day of the month   01 - 31*/
    int tm_mon;         /* month               0 - 11*/
    int tm_year;        /* year                距离1990年的数*/
    int tm_wday;        /* day of the week     0 - 6*/
    int tm_yday;        /* day in the year     0 - 355*/
    int tm_isdst;       /* daylight saving time */
    };

 3.  struct timeval {

          time_t tv_sec;                      /* seconds (秒)*/

          suseconds_t tv_usec;          /* microseconds(微秒) */

         };

 4.  struct timezone {

           int tz_minuteswest; /* minutes west of Greenwich */

           int tz_dsttime; /* type of DST correction */

           };

       

 

1. time_t time(time_t * timer)

       头文件:#include <time.h>  

       time_t : long 

       函数返回从1970-1-1 0:0:0开始到现在的秒数,如果参数timer不为空的话,返回的结果也会存在参数中。

2.  struct tm *localtime(const time_t *timep)

       头文件:#include <time.h>

       函数功能:将timep的时间转换为tm类型的时间

3.   struct tm *localtime_r(const time_t *timep, struct tm *result)

       头文件:#include <time.h>

       函数功能:同上

4. char *asctime(const struct tm *tm) 

    char *asctime_r(const struct tm *tm, char *buf)

       头文件:#include <time.h>

       函数功能:将time转为字符串形式的格式

       效果: Sat Aug  3 23:13:19 2019

5.char *ctime(const time_t *timep)

   char *ctime_r(const time_t *timep, char *buf);

    头文件:#include <time.h>

    函数功能:将time_t 类型的时间转换为现实世界使用的日期字符串

    效果:Sat Aug  3 23:20:18 2019

6. time_t mktime(struct tm *tm) 

    头文件:#include <time.h>

    函数功能:将时间结构体struct tm的值转化为经过的秒数

7. int gettimeofday(struct timeval *tv, struct timezone *tz)

     头文件:#include <time.h>

     函数功能:gettimeofday函数获取当前时间存于tv结构体中,相应的时区信息则存于tz结构体中 需要注意的是tz是依赖于系统,不同                           的系统可能存在获取不到的可能,因此通常设置为NULL

复制代码

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值