D
deepak.upp
Hi All,
I am trying to set time using clock_settime or settimeofday on a 64-
bit (Red Hat, 2.6.9-55.ELsmp) linux machine. I have a long seconds
value based on which system time needs to be changed I observed that
time being set is 1 Second less then as expected. Below is the code
snippet and output. Kindly suggest a solution for the same.
No such problem has been observed on a 32-bit machine.
#include <stdio.h>
#include<sys/time.h>
#include<time.h>
int main()
{
struct timespec tsTime_To_Set;
time_t temptime, temp;
int iRetCode = 0;
struct timeval tsTime_To_Set1;
temp = 1262284200;
tsTime_To_Set.tv_sec = temp;
tsTime_To_Set.tv_nsec = 0;
tsTime_To_Set1.tv_sec = temp;
tsTime_To_Set1.tv_usec = 0;
// iRetCode = clock_settime(CLOCK_REALTIME, &tsTime_To_Set);
iRetCode = settimeofday(&tsTime_To_Set1, NULL);
if (iRetCode == 0)
{
printf("\nclock_settime() returned success :%d",iRetCode);
}
temptime = time(0);
printf("\nCurrent Time set is=%s", ctime(&temptime));
printf("Seconds value decoded returns this time\n");
printf("%s", ctime(&temp));
}
OUTPUT-
clock_settime() returned success :0
Current Time set is=Thu Dec 31 23:59:59 2009
Seconds value decoded returns this time
Fri Jan 1 00:00:00 2010
I am trying to set time using clock_settime or settimeofday on a 64-
bit (Red Hat, 2.6.9-55.ELsmp) linux machine. I have a long seconds
value based on which system time needs to be changed I observed that
time being set is 1 Second less then as expected. Below is the code
snippet and output. Kindly suggest a solution for the same.
No such problem has been observed on a 32-bit machine.
#include <stdio.h>
#include<sys/time.h>
#include<time.h>
int main()
{
struct timespec tsTime_To_Set;
time_t temptime, temp;
int iRetCode = 0;
struct timeval tsTime_To_Set1;
temp = 1262284200;
tsTime_To_Set.tv_sec = temp;
tsTime_To_Set.tv_nsec = 0;
tsTime_To_Set1.tv_sec = temp;
tsTime_To_Set1.tv_usec = 0;
// iRetCode = clock_settime(CLOCK_REALTIME, &tsTime_To_Set);
iRetCode = settimeofday(&tsTime_To_Set1, NULL);
if (iRetCode == 0)
{
printf("\nclock_settime() returned success :%d",iRetCode);
}
temptime = time(0);
printf("\nCurrent Time set is=%s", ctime(&temptime));
printf("Seconds value decoded returns this time\n");
printf("%s", ctime(&temp));
}
OUTPUT-
clock_settime() returned success :0
Current Time set is=Thu Dec 31 23:59:59 2009
Seconds value decoded returns this time
Fri Jan 1 00:00:00 2010