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)
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;
}
Another alternative: Boost.Date_Time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With