#define _POSIX_C_SOURCE 200112L // 为 GCC 的 setenv #include #include #include #include int main(void) { char *strFileName = "/home/basic/wk/basic/test/test_time.c"; char *dir = dirname(strdup(strFileName) ); printf("dir = %s\n", dir); char *dirc, *basec, *bname, *dname; char *path = "/home/basic/wk/basic/test/test_time.c"; dirc = strdup(path); basec = strdup(path); dname = dirname(dirc); bname = basename(basec); printf("dirname=%s, basename=%s\n", dname, bname); // setenv("TZ", "/usr/share/zoneinfo/America/New_York", 1); // POSIX 限定 // struct tm tm = *localtime(&(time_t){time(NULL)}); // printf("%d\n", tm.tm_year); // 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 落在正常范围外 // mktime(&tm); // tm_dst 不被设为 -1 ;使用今日的 DST 状态 // printf("100 months ago was %s", asctime(&tm)); // printf("(DST was %s)\n", tm.tm_isdst ? "in effect" : "not in effect"); }