[comp.lang.c] Time format conversion problem

pnl@hpfinote.HP.COM (Peter Lim) (05/06/90)

I'm having a bit of problem with time in C. Consider the following 
program fragment.


#include <time.h>

struct	tm	the_time;
long	time_in_long;

/* To convert time_in_long to the_time, I use .... */
the_time = localtime (&time_in_long);

/* To convert the_time to time_in_long, what do I do ?? */
time_in_long = XXXXXX (&the_time);


I found that in Microsoft or Zortech C, XXXXXX() is mktime(); but
I need to move the program to a UNIX environment which doesn't have
mktime(). So, I'm stuck.

Anybody know which library function works the same as mktime(), 
or have some C code to replace the function ??

My UNIX manual says that time_in_long should store the value of the
time in seconds from 00:00:00 January 1, 1970. If this help ?


Regards,                       ## Life is fast enough as it is ........
Peter Lim.                     ## .... DON'T PUSH IT !!          >>>-------,
                               ########################################### :
E-mail:  plim@hpsgwg.HP.COM     Snail-mail:  Hewlett Packard Singapore,    :
Tel:     (065)-279-2289                      (ICDS, ICS)                   |
Telnet:        520-2289                      1150 Depot Road,           __\@/__
  ... also at: pnl@hpfipnl.HP.COM            Singapore   0410.           SPLAT !

henry@utzoo.uucp (Henry Spencer) (05/08/90)

In article <15080011@hpfinote.HP.COM> pnl@hpfinote.HP.COM (Peter Lim) writes:
>I found that in Microsoft or Zortech C, XXXXXX() is mktime(); but
>I need to move the program to a UNIX environment which doesn't have
>mktime(). So, I'm stuck.
>
>Anybody know which library function works the same as mktime(), 
>or have some C code to replace the function ??

mktime() is the ANSI C library function for this job.  On old systems,
including most current Unixes, there simply isn't one.
-- 
If OSI is the answer, what is |     Henry Spencer at U of Toronto Zoology
the question?? -Rolf Nordhagen| uunet!attcan!utzoo!henry henry@zoo.toronto.edu