/* ** timeofday */ #include #include #include #include static void old_timeofday() { struct timeval tp; struct timezone tpz; char templ[100]; char buf[100]; gettimeofday(&tp, &tpz); strftime(templ, sizeof(templ), "%a %b %d %H:%M:%S.%%06d %Y %Z", localtime((time_t *) &tp.tv_sec)); snprintf(buf, sizeof(buf), templ, tp.tv_usec); printf("old: >>%s<<\n", buf); }/*old_timeofday*/ static void new_timeofday() { struct timeval tp; struct timezone tpz; char templ[100]; char buf[100]; time_t tt; gettimeofday(&tp, &tpz); tt = tp.tv_sec; strftime(templ, sizeof(templ), "%a %b %d %H:%M:%S.%%06d %Y %Z", localtime(&tt)); snprintf(buf, sizeof(buf), templ, tp.tv_usec); printf("new: >>%s<<\n", buf); }/*new_timeofday*/ int main(int argc, char *argv[]) { old_timeofday(); new_timeofday(); }/*main*/