#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
int main( void )
{
struct timespec stime;
struct tm *ptm;
time_t tvtmp, tvsec;
ptm=localtime(&tvtmp);
ptm->tm_hour = 14;
ptm->tm_min = 30;
ptm->tm_year = 2015-1900;
tvsec = mktime(ptm);
stime.tv_sec = tvsec; /* Add one day */
stime.tv_nsec = 0;
if( clock_settime( CLOCK_REALTIME, &stime) == -1 ) {
perror( "setclock" );
return EXIT_FAILURE;
}
printf("Currenttime=%s",asctime(ptm));
return EXIT_SUCCESS;
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
int main( void )
{
struct timespec stime;
struct tm *ptm;
time_t tvtmp, tvsec;
ptm=localtime(&tvtmp);
ptm->tm_hour = 14;
ptm->tm_min = 30;
ptm->tm_year = 2015-1900;
tvsec = mktime(ptm);
stime.tv_sec = tvsec; /* Add one day */
stime.tv_nsec = 0;
if( clock_settime( CLOCK_REALTIME, &stime) == -1 ) {
perror( "setclock" );
return EXIT_FAILURE;
}
printf("Currenttime=%s",asctime(ptm));
return EXIT_SUCCESS;
}
注:时区需要注意TZ=CCT-8