Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

mktime() alternative???

637 views
Skip to first unread message

Tony R. Bennett

unread,
Jun 7, 2000, 3:00:00 AM6/7/00
to

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");
}


TIA,
-tony
--
Anti-spam filter: I am not root@localhost
trb@teleport dot com COM Public Access User --- Not affiliated with Teleport

Dan Forrest

unread,
Jun 7, 2000, 3:00:00 AM6/7/00
to
t...@user2.teleport.com (Tony R. Bennett) writes:

> 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

0 new messages