In the process of using cocos2d-x, want to calculate time difference, such as Touchbegin and touchend click Time difference, need to get the current times, this time is usually used to obtain, return unit is time_t on the iOS platform looked down, That is, long, which is the number of seconds starting from January 1, 1970. But this time is not very accurate, can only be accurate to the second.
If you want to be in milliseconds, or microseconds, there are functions like GetTickCount (Windows platform).
Google a bit, found a C function: clock_t clock (void);
The function returns a clock_t type, which is also a long, and how much time does it know how to represent the return value.
Here is a macro, clocks_per_sec is obviously a second how many clocks meaning, then we have to get the current in seconds to do the time to do the unit, the code is as follows:
float curtimesec = (float) click ()/(float) clocks_per_sec;