I am trying to generate a Common Log File. TO do this i need the Date in this form:
[day/month/year:hh:mm:ss zone]
For example, [08/May/1997:16:27:54 +0100]
How can i get C to do this simply?
thanks
Printable View
I am trying to generate a Common Log File. TO do this i need the Date in this form:
[day/month/year:hh:mm:ss zone]
For example, [08/May/1997:16:27:54 +0100]
How can i get C to do this simply?
thanks
Try:
Code:#include <time.h>
#include <stdio.h>
#include <stdlib.h>
int main(void){
char tmp[120];
char tmzone[4];
time_t lt;
struct tm *tmptr;
memset(tmp,0x00,sizeof(tmp));
memset(tmzone,0x00,sizeof(tmzone));
lt = time(NULL); // time now
tmptr=localtime(<);
// make this format: [day/month/year:hh:mm:ss zone]
strftime(tmzone,sizeof(tmzone),"%Z",tmptr);
strftime(tmp,sizeof(tmp),"[%d/%b/%Y:%H:%M:%S ",tmptr);
strcat(tmp,tmzone);
strcat(tmp,"]");
printf("%s\n",tmp);
return 0;
}
nice, except that tmzone should be at least 6 chars long...