#include <stdio.h>
#include <time.h>
int main ()
{
time_t rawtime; //时间类型(time.h 定义)
struct tm*timeinfo; //时间结构,time.h 定义如下:
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
time (&rawtime );// 获取时间,以秒计,从1970年1月一日起算,存于rawtime
timeinfo=localtime (&rawtime ); //转为当地时间,tm 时间结构
//asctime(timeinfo);//转为标准ASCII时间格式:
printf ( "The current date/time is: %s", asctime (timeinfo) );
return 0;
}

#define BUFLEN 255
#include<stdio.h>
#include<time.h>
int main()
{
time_t t = time( 0 );
char tmpBuf[BUFLEN];
strftime(tmpBuf, BUFLEN, "%Y-%m-%d %H:%M:%S", localtime(&t)); //format date and time.
printf("time is [%s]",tmpBuf);
return 0;
}
