Question

How do I format a time_t structure to something like this year-month-day h:m:s, I have already tried using ctime:

time_t t = time((time_t*) NULL);
char *t_format = ctime(&t);

but it doesn't give me the desired results

example : 2011-11-10 10:25:03. What I need is a string containing the result so I can write it to a file. Thanks

Was it helpful?

Solution

Use strftime from time.h like so:

char tc[256];
strftime(tc, 256, "%Y-%m-%d %H:%M:%S", tm);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top