what is the difference between gmtime() and localtime?

I thought that the gmtime( ) returns without the timezone consideration and
the localtime should,but the result of the following codes confused me:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

time_t nowtime;
struct tm *gmt,*lct;

main()

{
nowtime=time(NULL);
gmt=gmtime(&nowtime);
lct=localtime(&nowtime);
if((memcmp(gmt,lct,sizeof(struct tm)))==0) {
fprintf (stdout,“the gmtime and the localtime are the same\n”);
}
else {
fprintf (stdout,“the gmtime and the localtime have some
difference\n”);
}
return 0;

}

no matter how I changed the timezone setting,the codes tell me “the gmtime
and the localtime are the same”.
What is the problem?

“Masmito” <Mssmittomail@hotmail.com> wrote in message
news:aaikpd$bl4$1@inn.qnx.com

I thought that the gmtime( ) returns without the timezone consideration
and
the localtime should,but the result of the following codes confused me:

#include <stdio.h
#include <stdlib.h
#include <time.h

time_t nowtime;
struct tm *gmt,*lct;

main()

{
nowtime=time(NULL);
gmt=gmtime(&nowtime);
lct=localtime(&nowtime);
if((memcmp(gmt,lct,sizeof(struct tm)))==0) {
fprintf (stdout,“the gmtime and the localtime are the same\n”);
}
else {
fprintf (stdout,“the gmtime and the localtime have some
difference\n”);
}
return 0;

}

no matter how I changed the timezone setting,the codes tell me “the gmtime
and the localtime are the same”.
What is the problem?

Those functions return pointer, you have to copy data it is pointing to
somewhere, before isueing tha call again.

e.g
struct tm gmt, lct, *tmp;
tmp = gmtime();
memcpy(&gmt, tmp, sizeof…)
tmp = localtime();
memcpy(&lct, tmp, sizeof…)

memcmp(&gmt, &lct, …)

Pavol Kycina

Masmito <Mssmittomail@hotmail.com> wrote:

I thought that the gmtime( ) returns without the timezone consideration and
the localtime should,but the result of the following codes confused me:

#include <stdio.h
#include <stdlib.h
#include <time.h

time_t nowtime;
struct tm *gmt,*lct;

main()

{

call tzset() here

nowtime=time(NULL);
gmt=gmtime(&nowtime);
lct=localtime(&nowtime);
if((memcmp(gmt,lct,sizeof(struct tm)))==0) {
fprintf (stdout,“the gmtime and the localtime are the same\n”);
}
else {
fprintf (stdout,“the gmtime and the localtime have some
difference\n”);
}
return 0;

}

no matter how I changed the timezone setting,the codes tell me “the gmtime
and the localtime are the same”.
What is the problem?