日期:2014-05-16 浏览次数:20727 次
/*
* 获得本地时间
* 返回字符串格式"年_月_日"
*/
char *get_local_time_y_m_d()
{
time_t *the_time;
struct tm tm_ymd;
char *buf;
the_time=(time_t *)malloc(sizeof(time_t));
//tm_ymd=(struct tm *)malloc(sizeof(struct tm));
buf=(char *)malloc(sizeof(char)*16);
memset(buf,'\0',sizeof(char)*16);
//printf("%p\n%p\n",the_time,tm_ptr);
time(the_time);
//tm_ymd=gmtime(the_time);
localtime_r(the_time,&tm_ymd);
//memcpy(tm_ymd,localtime(the_time),sizeof(struct tm));
strftime(buf,16,"%Y_%m_%d",&tm_ymd);
free(the_time);
/*
* 看样子struct tm 结构似乎不能free
*/
//free(tm_ptr);
return buf;
}
/*
* 获得本地时间
* 返回字符串格式"时_分_秒"
*/
char *get_local_time_h_m_s()
{
time_t *the_time;
struct tm tm_hms;
char *buf;
the_time=(time_t *)malloc(sizeof(time_t));
//tm_hms=(struct tm *)malloc(sizeof(struct tm));
buf=(char *)malloc(sizeof(char)*16);
memset(buf,'\0',sizeof(char)*16);
//printf("%p\n%p\n",the_time,tm_ptr);
time(the_time);
//tm_hms=gmtime(the_time);
localtime_r(the_time,&tm_hms);
//memcpy(tm_hms,localtime(the_time),sizeof(struct tm));
strftime(buf,16,"%H:%M:%S",&tm_hms);
free(the_time);
/*
* 看样子struct tm 结构似乎不能free
*/
//free(tm_ptr);
return buf;
}