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?
what is the difference between gmtime() and localtime?
Re: what is the difference between gmtime() and localtime?
"Masmito" <Mssmittomail@hotmail.com> wrote in message
news:aaikpd$bl4$1@inn.qnx.com...
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
news:aaikpd$bl4$1@inn.qnx.com...
Those functions return pointer, you have to copy data it is pointing toI 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?
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
Re: what is the difference between gmtime() and localtime?
Masmito <Mssmittomail@hotmail.com> wrote:
call tzset() hereI 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?