P
Paul N
I'm trying to write a program that will show the time at various
different places. The idea is to get the GMT time, adjust it for the
correct time zone offset (including DST if appropriate) and display
it. My first attempt (limited to BST) would use gmtime to get GMT, add
1 to the tm_hour member, knock off 24 if the adjusted hour exceeded
23, and show it. This worked OK. However, I discovered the function
mktime which I though might provide a more general solution. As I
understand it, if you pass it a struct in which the number of the hour
is outside the proper range, it will adjust things so that it isn't.
Unfortunately it's not doing what I want. In the following code:
struct tm *t;
time_t lTime;
time(&lTime);
t = gmtime(&lTime);
mktime(t);
it is showing an hour ahead of GMT. Whereas if I comment out the
mktime line it shows GMT correctly. I've tried setting t -> tm_isdst =
0; between the gmtime and the mktime but this doesn't help. Why is
mktime changing the time it is passed in? (By the way, my actual time
zone is BST, ie currently one hour ahead of GMT.)
Am I using it wrong, or am I misunderstanding what it's meant to do?
Thanks for any help.
Paul.
different places. The idea is to get the GMT time, adjust it for the
correct time zone offset (including DST if appropriate) and display
it. My first attempt (limited to BST) would use gmtime to get GMT, add
1 to the tm_hour member, knock off 24 if the adjusted hour exceeded
23, and show it. This worked OK. However, I discovered the function
mktime which I though might provide a more general solution. As I
understand it, if you pass it a struct in which the number of the hour
is outside the proper range, it will adjust things so that it isn't.
Unfortunately it's not doing what I want. In the following code:
struct tm *t;
time_t lTime;
time(&lTime);
t = gmtime(&lTime);
mktime(t);
it is showing an hour ahead of GMT. Whereas if I comment out the
mktime line it shows GMT correctly. I've tried setting t -> tm_isdst =
0; between the gmtime and the mktime but this doesn't help. Why is
mktime changing the time it is passed in? (By the way, my actual time
zone is BST, ie currently one hour ahead of GMT.)
Am I using it wrong, or am I misunderstanding what it's meant to do?
Thanks for any help.
Paul.