Link to home
Start Free TrialLog in
Avatar of nerdmike
nerdmike

asked on

ANSI C get system time

Hi

I'm looking for a way (ideally using ANSI C) to gather the system time, and print it in a human readable form.

-Mike
Avatar of cookre
cookre
Flag of United States of America image

For pure ANSI, you want time():
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_time.asp?frame=true

If you're willing to live in the MS world, strtime():
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_crt__strtime.2c_._wstrtime.asp?frame=true

gives it to you already in a string, but it's not standard ANSI.
Avatar of _iskywalker_
_iskywalker_

on unixes try
 int gettimeofday(struct timeval *tv, struct timezone *tz);
where timeval is:
 struct timeval {
               time_t         tv_sec;        /* seconds */
               suseconds_t    tv_usec;  /* microseconds */
       };
an example:
struct timeval now;
 gettimeofday (&now, NULL);
fprintf(stderr," %i %i \n", now.tv_sec, now.tv_usec);

on windows that could also work...
  struct timeval tv;
  gettimeofday (&tv, NULL);
ASKER CERTIFIED SOLUTION
Avatar of brettmjohnson
brettmjohnson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nerdmike

ASKER

According to man ctime, it requires a CLOCK object pointer. Time() returns a time_t type, I don't think thats right.
wait, nevermind.