• C语言中 time相关的函数 头文件


    1.  time相关的函数在 time.h 中可以查看原型。如下命令可以找出time.h的路径:

    whereis time.h

    2. 先看代码,要包含time.h

    ===================================

    void main() {
        struct timeval val;
        gettimeofday(&val, NULL);
        printf("sec=%ld, usec=%ld ", val.tv_sec, val.tv_usec);

        time_t  rawtime; // long type
        time ( &rawtime );
        printf("rastime = %ld ", rawtime);

        struct tm * timeinfo;   

        timeinfo = localtime ( &rawtime );

        printf("%d-%d-%d %d:%d:%d ", timeinfo->tm_year+1900, timeinfo->tm_mon+1,
             timeinfo->tm_mday, timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
        printf ( "The current date/time is: %s", asctime (timeinfo) );
    }

    ======================================
    说明:
    1> time_t实际上是长整数类型,定义为:typedef long time_t;

    time_t 定义的数值也可以 使用 struct timeval.tv_sec 来代替。
     
    int gettimeofday(struct timeval*tv, struct timezone *tz); //tz 常设置为NULL
    struct timeval
    {
         __time_t tv_sec;               
         __suseconds_t tv_usec;     
    };

    2>
    localtime 函数原型:struct tm *localtime(const time_t *timer)

    3>
    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;          
    };

    4>

    asctime()函数

      功 能: 转换日期和时间为相应的字符串(英文简写形式,形如:Mon Feb 16 11:29:26 2009)

      用 法: char *asctime(const struct tm *tblock);


    参考博客:
    https://www.cnblogs.com/wainiwann/archive/2012/11/28/2792133.html

  • 相关阅读:
    性能测试入门
    PHP基础
    SpringCloud五大核心组件
    selenium(八)持续集成
    四种隔离级别和脏读、幻读、不可重复读
    RocketMQ【目录】
    ModelAgnostic Counterfactual Reasoning for Eliminating Popularity Bias in Recommender System
    How Powerful is Graph Convolution for Recommendation?
    ScoreBased Generative Modeling through Stochastic Differential Equations
    Graph Embedding for Recommendation against Attribute Inference Attacks
  • 原文地址:https://www.cnblogs.com/jyfyonghu/p/10834797.html
Copyright © 2020-2023  润新知