Dates are used as values in several HTTP headers. The proper format for a date is as follows:
Tue, 21 May 2002 12:34:56 GMT
类似于格林威治时间格式但又不太一样
int _tmain(int argc, _TCHAR* argv[])
{
char *wDay[] = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
char *wMonth[] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
time_t timep;
struct tm *p;
time(&timep);
p = localtime(&timep); /*取得当地时间*/
printf("%s, %d %s %d %d:%d:%d GMT",wDay[p->tm_wday],p->tm_mday,wMonth[p->tm_mon],(1900 + p->tm_year),p->tm_hour, p->tm_min, p->tm_sec);
system("pause");
return 0;
}
localtime_s()的用法:
int _tmain(int argc, _TCHAR* argv[])
{
char *wDay[] = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
char *wMonth[] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
time_t timep;
struct tm *p = (tm*)calloc(1,sizeof(tm));
time(&timep);
localtime_s(p,&timep); /*取得当地时间*/
printf("%s, %d %s %d %d:%d:%d GMT",wDay[p->tm_wday],p->tm_mday,wMonth[p->tm_mon],(1900 + p->tm_year),p->tm_hour, p->tm_min, p->tm_sec);
//lt=time(NULL);/*system time and date*/
//printf(ctime(<)); /*english format output*/
//printf(asctime(localtime(<))); /*locale*/
system("pause");
return 0;
}
评论