功 能: 把日期和时间转变为结构
用 法: struct tm *localtime(const time_t *timep);
函数名:strftime
功 能:格式化日期和时间
用 法:size_t strftime(char *s, size_t max, const char *format, const struct tm *tm);
#include
#include
int main(void)
{
time_t timer;
struct tm *tblock;
char cur_date[64];
/* gets time of day */
time(&timer);
/* converts date/time to a structure */
tblock = localtime(&timer);
printf("Local time is: %s", asctime(tblock));
/* */
strftime(cur_date, sizeof(cur_date), "%Y-%m-%d %H:%M:%S", tblock);
printf("Local time is: %s\n", cur_date);
return 0;
}
阅读(1005) | 评论(0) | 转发(0) |