获取当前时间戳

#include <stdio.h>
#include <stdlib.h>

#define _POSIX_C_SOURCE 200112L // for setenv on gcc
#include <stdlib.h>
#include <stdio.h>
#include <time.h>

int main(void)
{
    
    time_t t = time(NULL); 
    struct tm* tm = localtime(&t);
   
    printf("Today is           %s", asctime(tm));
    printf("(DST is %s)\n", tm->tm_isdst ? "in effect" : "not in effect");
    tm->tm_mon -= 100;  // tm_mon is now outside its normal range
    mktime(tm);       // tm_dst is not set to -1; today's DST status is used
    printf("100 months ago was %s", asctime(tm));
    printf("(DST was %s)\n", tm->tm_isdst ? "in effect" : "not in effect");
}

 

posted on 2023-05-22 19:48  邗影  阅读(7)  评论(0编辑  收藏  举报

导航