C时间函数

来源:互联网 发布:金百福珠宝软件试用版 编辑:程序博客网 时间:2024/06/05 15:49

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


#include <stdio.h>#include <time.h>#include <assert.h>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);}


0 0
原创粉丝点击