hallo all,
i'm a new member.
i need help in my program
i want 2 know if there is a datatype called time.
my program will deal with time as below
11:33:50,965
it will read 2 absolute times for 2 actions and then return the differnce.
how can i do that.

example for the input file:
action y 11:22:50,333
action x 11:22:55,400


and it must read the 2 actions and then return the diffrence in millisecond:rolleyes:

look up <time.h> - it includes a data type time_t - however, that is only accurate to a second AFAIK. if you need anything more accurate, you'll need to create your own, or find a 3rd party library.

in MS-Windows you can call win32 api function GetSystemTime() that returns a SYSTEMTIME structure. Other operating systems probably have something similar, but I don't know what they would be.

// I think clock() is only available for Windows, a tick is ~ 1 ms
// if you need time like the string returned by ctime(), then you have to do some processing

#include <iostream>
#include <ctime>      // clock(), time(), ctime(), time_t 

using namespace std; 
 
int main()
{
  time_t t;

  time(&t);
  cout << "Today's date and time: " << ctime(&t) << endl;

   
  int clo(clock());         // start clock


  // put your function to be timed here


  int clo2(clock() - clo); // difference end clock - start clock

  cout << "time elapsed = " << clo2 << " ticks" << endl;

  cin.get();   // wait for key press
}

>>// I think clock() is only available for Windows,

clock() does NOT give you current date/time. It will only give you the number of milliseconds since your computer was last booted, or some rollover value.

This article has been dead for over six months. Start a new discussion instead.