|
-
May 15th, 2002, 06:27 PM
#1
I need C to generate the Date in a certain format
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
-
May 16th, 2002, 10:05 AM
#2
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;
}
-
May 24th, 2002, 07:49 AM
#3
nice, except that tmzone should be at least 6 chars long...
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|