linux修改时间
修改时间前,必须确定当前用户具有相应权限。
#include <stdio.h>#include <string.h>#include <stdlib.h>#include <time.h>#include <sys/time.h> int main(int argc, char *argv[]){ time_t mytime = time(0); struct tm* tm_ptr = localtime(&mytime); if (tm_ptr) { tm_ptr->tm_mon = 5; tm_ptr->tm_mday = 1; const struct timeval tv = {mktime(tm_ptr), 0}; settimeofday(&tv, 0); } return 0;}