/* * Sample program for stime system call - No.25 * * stime - set time * * Synopsis * #define _SVID_SOURCE * glibc2 needs this * * #include * * int stime(time_t *t); * * Description * stime sets the system's idea of the time and date. Time, * pointed to by t, is measured in seconds from 00:00:00 GMT * January 1, 1970. stime() may only be executed by the super * user. */ #include #include main() { int hour; struct tm *now; time_t timer; timer = time(NULL); now = localtime(&timer); /* menbers of sturct tm */ printf("tm_sec = %d\n", now->tm_sec); printf("tm_min = %d\n", now->tm_min); printf("tm_hour = %d\n", now->tm_hour); printf("tm_mday = %d\n", now->tm_mday); printf("tm_mon = %d\n", now->tm_mon); printf("tm_year = %d\n", now->tm_year); printf("tm_wday = %d\n", now->tm_wday); printf("tm_yday = %d\n", now->tm_yday); printf("tm_isdst = %d\n", now->tm_isdst); printf("tm_gmtoff = %ld\n", now->tm_gmtoff); printf("tm_zone = %s\n", now->tm_zone); printf("%s", asctime(localtime(&timer))); hour = now->tm_hour; now->tm_hour = (hour + 1) % 24; timer = mktime(now); stime(&timer); time(&timer); printf("%s", asctime(localtime(&timer))); hour = now->tm_hour; now->tm_hour = (hour - 1) % 24; timer = mktime(now); stime(&timer); time(&timer); printf("%s", asctime(localtime(&timer))); }