Apparently the mktime() function assumes its 'struct tm' parameter is in
local time and uses this when building its time_t return which is
in UTC/GMT.
What I need is a flavor of mktime() that takes a 'struct tm' that is NOT
in local time...i.e.: in UTC/GMT ... and still produces a time_t in
UTC/GMT.
I understand that FreeBSD has a function called 'timegm()' that does
this... Is there a similar function available for AIX ???
Here's an example:
time_t my_time_t_b4 = 0;
time_t my_time_t_after;
struct tm my_tm;
my_tm = gmtime( &(my_time_t_b4));
my_time_t_after = mktime(my_tm);
if ( my_time_t_b4 != my_time_t_after )
{
printf("double conversion failed\n");
}else{
printf("double conversion succeeded\n");
}
TIA,
-tony
--
Anti-spam filter: I am not root@localhost
trb@teleport dot com COM Public Access User --- Not affiliated with Teleport
> I previously posted this question to commp.unix.programming
> but got an answer that apparently AIX doesn't support...
> ...So, forgive the cross post.
>
> Apparently the mktime() function assumes its 'struct tm' parameter is in
> local time and uses this when building its time_t return which is
> in UTC/GMT.
>
> What I need is a flavor of mktime() that takes a 'struct tm' that is NOT
> in local time...i.e.: in UTC/GMT ... and still produces a time_t in
> UTC/GMT.
>
> I understand that FreeBSD has a function called 'timegm()' that does
> this... Is there a similar function available for AIX ???
>
> Here's an example:
> time_t my_time_t_b4 = 0;
> time_t my_time_t_after;
> struct tm my_tm;
>
> my_tm = gmtime( &(my_time_t_b4));
> my_time_t_after = mktime(my_tm);
>
> if ( my_time_t_b4 != my_time_t_after )
> {
> printf("double conversion failed\n");
> }else{
> printf("double conversion succeeded\n");
> }
If you add:
putenv("TZ=GMT");
before the call to "mktime", it will work.
--
Dan