In the following code, I try to get the local time and greenwich time and find the difference between them. But the output shows both the time values are equal:
diff=0 iTm1=16:34 iTm2=16:34 <-----[gmtime is 13:34 actualy]
When I just retreive gmtime, it works correctly. But when I retreive both local and gmtime, gmtime becomes equal to localtime.
#include <stdio.h>
#include <time.h>
int main()
{
time_t iTime;
struct tm * iTm1;
struct tm * iTm2;
int iTimeDifferenceInMinutes;
time(&iTime);
iTm1=gmtime(&iTime);
iTm2=localtime(&iTime);
iTimeDifferenceInMinutes=(int)((iTm2->tm_hour - iTm1->tm_hour)) * 60;
printf("diff=%d iTm1=%d:%d iTm2=%d:%d\n", iTimeDifferenceInMinutes,
iTm1->tm_hour, iTm1->tm_min,
iTm2->tm_hour, iTm2->tm_min);
}
I have a mistake but I couldn't find it... May someone show me my fault please..?