I need to generate time-stamp in this format yyyymmdd. Basically I want to create a filename with current date extension. (for example: log.20100817)
+13
A:
http://www.cplusplus.com/reference/clibrary/ctime/strftime/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
char date[9];
time_t t = time(0);
struct tm *tm;
tm = gmtime(&t);
strftime(date, sizeof(date), "%Y%m%d", tm);
printf("log.%s\n", date);
return EXIT_SUCCESS;
}
Brandon Horsley
2010-08-17 17:56:31
caf
2010-08-18 02:18:24