date -s 修改时间

date -s “2016-4-18 15:14:23”

   char itmp1[5],itmp2[5],itmp3[5],itmp4[5],itmp5[5],itmp6[5];
    itmp1 = atoi(tmp1);
    itmp2 = atoi(tmp2);
    itmp3 = atoi(tmp3);
    itmp4 = atoi(tmp4);
    itmp5 = atoi(tmp5);
    itmp6 = atoi(tmp6);
    /* 使用程序设置系统时间的功能已经实现
    struct tm p;
    struct timezone tz;
    time_t timep;
    struct timeval tv,tt;
    p.tm_year = itmp1 - 1900;
    p.tm_mon = itmp2 - 1;
    p.tm_mday = itmp3;
    p.tm_hour = itmp4;
    p.tm_min = itmp5;
    p.tm_sec = itmp6;
    timep = mktime(&p);
    tv.tv_sec = timep;
    tv.tv_usec = 0;
    gettimeofday(&tt, &tz);
    settimeofday(&tv, &tz);
    */
    sprintf(syscmd,"date -s \"%d-%d-%d %d:%d:%d\"", itmp1, itmp2, itmp3, itmp4, itmp5, itmp6);
    system(syscmd);
    system("hwclock -w");

你可能感兴趣的:(linux,shell)