Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 717
  • Last Modified:

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
0
nerdmike
Asked:
nerdmike
1 Solution
 
cookreCommented:
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.
0
 
_iskywalker_Commented:
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);
0
 
brettmjohnsonCommented:
The ANSI C standard way to print the current time in human readable form:
use time() and ctime():


#include <time.h>

printf("The current time is: %s\n", ctime(time(NULL)));

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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now