local_time

time_t time(time_t *tloc);

功能:获取纪元1970-01-01 00:00:00以来所经历的秒数

参数:

tloc:用来存储返回时间

返回值:成功:返回秒数, 失败:-1

-------------------------------------------------------------------------------------------------------

struct tm *localtime(const time_t *timep);
struct tm *localtime_r(const time_t *timep, struct tm *result);

struct tm {
int tm_sec; /* Seconds (0-60) */
int tm_min; /* Minutes (0-59) */
int tm_hour; /* Hours (0-23) */
int tm_mday; /* Day of the month (1-31) */
int tm_mon; /* Month (0-11) */
int tm_year; /* Year - 1900 */
int tm_wday; /* Day of the week (0-6, Sunday = 0) */
int tm_yday; /* Day in the year (0-365, 1 Jan = 0) */
int tm_isdst; /* Daylight saving time */
};

---------------------------------------------------------------------------------------------------

#include <stdio.h>
#include <time.h>

int main()
{
time_t stim;
time(&stim);
struct tm *stm, *stm2;
stm = localtime(&stim);
printf("%04d-%02d-%02d %02d:%02d:%02d\n", stm->tm_year + 1900, \
stm->tm_mon + 1, stm->tm_mday, stm->tm_hour, stm->tm_min,\
stm->tm_sec);
stm2 = localtime_r(&stim, stm2);
printf("%04d-%02d-%02d %02d:%02d:%02d\n", stm2->tm_year + 1900, \
stm2->tm_mon + 1, stm2->tm_mday, stm2->tm_hour, stm2->tm_min,\
stm2->tm_sec);
return 0;
}
---------------------------------------------------------------------------------------------------------

posted @ 2019-12-17 10:30  MoonXu  阅读(162)  评论(0编辑  收藏  举报