Pregunta

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

¿Fue útil?

Solución

Use strftime from time.h like so:

char tc[256];
strftime(tc, 256, "%Y-%m-%d %H:%M:%S", tm);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top