time |
An os_time
represents a microsecond accuracy time between
00:00:00.000000 and 23:59:59.999999, and is similar in functionality to os_date
. Time arithmetic rolls
over, if necessary, so the result is always a valid time.
The following example illustrates some simple time functions. The output of this example varies depending upon the time of day.
#include <iostream>
#include <ospace/time.h>
void
main()
{
os_time_toolkit initialize;
cout << "min time = " << os_time::min_time << endl;
cout << "max time = " << os_time::max_time << endl;
os_time midnight; // Constructs by default to 00:00:00.000000.
os_time noon( 12, 0 ); // 12 o'clock.
os_time now = os_time::now(); // Current time.
cout << "midnight = " << midnight << ", noon = " << noon << endl;
cout << "now = " << now << endl;
cout << "midnight.is_pm() = " << midnight.is_pm() << endl;
cout << "noon.is_pm() = " << noon.is_pm() << endl;
cout << "now > noon = " << (now > noon) << endl; // Compare.
os_time_period period1 = now - noon; // Subtract.
cout << "now - noon = ";
cout << period1.to_seconds() << " seconds" << endl;
os_time delta( 13, 45, 23 ); // 13 hours, 45 minutes, 23 seconds.
cout << noon << " + " << delta << " = " << (noon + delta) << endl;
}
min time = 00:00:00
max time = 23:59:59
midnight = 00:00:00, noon = 12:00:00
now = 19:50:47
midnight.is_pm() = 0
noon.is_pm() = 1
now > noon = 1
now - noon = 28247 seconds
12:00:00 + 13:45:23 = 01:45:23
Copyright©1994-2026 Recursion
Software LLC
All Rights Reserved - For use by licensed users only.