- 论坛徽章:
- 0
|
求教,急!c下获取系统时间(日期)的简单方法?
- int GetDateYYYYMMDD()
- {
- time_t t;
- struct tm tt;
- time(&t);
- #ifdef SunOS
- memcpy(&tt, localtime(&t), sizeof(struct tm));
- #else
- localtime_r(&t, &tt);
- #endif
- return (tt.tm_year + 1900) * 10000 + (tt.tm_mon + 1) * 100 + tt.tm_mday;
- }
复制代码
如果想得到时间就参考tm结构
struct tm {
int tm_sec; /* seconds */
int tm_min; /* minutes */
int tm_hour; /* hours */
int tm_mday; /* day of the month */
int tm_mon; /* month */
int tm_year; /* year */
int tm_wday; /* day of the week */
int tm_yday; /* day in the year */
int tm_isdst; /* daylight saving time */
}; |
|