Wednesday, April 6, 2011

C: time/date string

http://www.thinkage.ca/english/gcos/expl/c/lib/strfti.html

#include <time.h>
length = strftime(string,maxlen,format,timestruct);

Examples:

#include <time.h> char s[30]; size_t i; struct tm tim; time_t now; now = time(NULL); tim = *(localtime(&now)); i = strftime(s,30,"%b %d, %Y; %H:%M:%S\n",&tim);

obtains the current date and time and puts it into "s" in a format like

Jan 10, 1987; 17:55:55\n




No comments: