Epoch is a high resolution, cross platform time library for C/C++. This library can provide time measurements of less than one microsecond (1E-6 seconds), as well as date and time information in both local and UTC time. See examples at the end to see the proper usage of functions and what header files to include.
- Essentially acts as a timer to hold elapsed time info
-
Holds current system time information.
typedef struct { unsigned short year; // current year unsigned short month; // current month (0-11) unsigned short weekday; // current weekday (0-6) unsigned short day; // current day (0-364) unsigned short hour; // current hour (0-23) unsigned short minute; // current minute (0-59) unsigned short second; // current second (0-59) } Epoch_SysInfo_t;
- Used to query system time information in local time (the time on your machine).
- Used to query system time information in universal coordinated time (UTC).
- Intializes internal variables for use. Needs to be called only once at the start of the program.
- Initializes an Epoch_t and resets it's elapsed time. This must be called to start an Epoch_t before it's elapsed time is ever queried.
- Gets the elapsed time from an Epoch_t.
- Fill a Epoch_SysInfo_t with system time information. "type" should be either EPOCH_LOCAL_TIME or EPOCH_UTC_TIME.
#include <stdio.h>
#include "epoch.h"
int main(int argc, char* argv[])
{
// Initialize Epoch
Epoch__Init();
// Create a new timer
Epoch_t timer;
// Start the timer
Epoch__Start(&timer);
// Keep track of elapsed time
double elapsed;
// Print out elapsed time
// for five seconds
do
{
// Get change in time since the
// timer was started
elapsed = Epoch__QueryChange(&timer);
printf("%f\n", elapsed);
}
while (elapsed < 5.0);
}
#include <stdio.h>
#include "epoch.h"
int main(int argc, char* argv[])
{
// Initialize Epoch
Epoch__Init();
// Used to hold system information
Epoch_SysInfo_t info;
// Get current system information (local time)
Epoch__QuerySysInfo(&info, EPOCH_LOCAL_TIME);
// Print some info
printf("Current Year: %d\n", info.year);
printf("Current Month: %d\n", info.month);
printf("Current Weekday: %d\n", info.weekday);
printf("Current Day: %d\n", info.day);
printf("Current Hour: %d\n", info.hour);
printf("Current Minute: %d\n", info.minute);
printf("Current Second: %d\n", info.second);
}