C时间函数

C的几个时间函数,写一段小代码,把其全部囊括。


#include 
#include 
#include 

int main()
{
    time_t now = time(NULL);
    printf("now utc is %d\n", now);

    struct tm* gtmie = gmtime(&now);
    struct tm* ctmie = localtime(&now);
    time_t now2 = mktime(gtmie );
    time_t now3 = mktime(ctmie );
    assert (now==now2);
    assert (now==now3);

    printf("Time now is %s\n", asctime(gtmie));
    printf("Time now is %s\n", asctime(ctmie));
    printf("Time now is %s\n", ctime(&now));


    char buf[124];
    size_t len;

    len = strftime(buf,124,"%Y-%m-%d %H:%M:%S %Z",gtmie);
    printf("Time now is %s\n",buf);


}


你可能感兴趣的:(C时间函数)