0

I have problems to finding any examples of creating a basic time_t function to count the seconds and milliseconds, both from a zero value. Does anyone has a basic example ?.

alk
  • 69,737
  • 10
  • 105
  • 255
Osman Esen
  • 1,704
  • 2
  • 21
  • 46
  • 1
    Can you elaborate on what you mean by "count the seconds" ? Can you show us how the prototype would look or how it would be called ? – cnicutar Jan 14 '14 at 17:40
  • Note that `time_t` is a type, not a function. There is a function [`time()`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/time.html) that returns a `time_t` value. You might need to look up [`localtime()`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/localtime.html), [`gmtime()`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/gmtime.html) and [`strtime()`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/strtime.html). Alternatively, you might need to look up [`clock()`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock.html). – Jonathan Leffler Jan 14 '14 at 17:40
  • Note that you've not specified you platform. On most Unix-like environments, there are other high-resolution timers too. Theoretically, using [`clock_gettime()`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_gettime.html) is best, but it is not portable to Mac OS X, whereas [`gettimeofday()`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/gettimeofday.html), although formally marked obsolescent, is available on essentially all Unix variants. Windows has its own, different set of APIs; I'm not familiar with the details. – Jonathan Leffler Jan 14 '14 at 17:46
  • I'm using Windows. What I mean is starting from a zero value, and then counting both the seconds and milliseconds. – Osman Esen Jan 14 '14 at 18:01
  • Try 1) http://stackoverflow.com/questions/1120478/capturing-a-time-in-milliseconds or 2) http://stackoverflow.com/questions/1444428/time-stamp-in-the-c-programming-language – chux - Reinstate Monica Jan 14 '14 at 23:38

0 Answers0