Time Shield Library
C++ library for working with time
Loading...
Searching...
No Matches
time_utils_example.cpp
Go to the documentation of this file.
1
6
7#include <iostream>
8
10
11int main() {
12 using namespace time_shield;
13
14 // Print different representations of the current time
15 std::cout << "Seconds since epoch: " << ts() << '\n';
16 std::cout << "Milliseconds since epoch: " << ts_ms() << '\n';
17 std::cout << "Microseconds since epoch: " << ts_us() << '\n';
18
19 // Show fractional parts of the current second
20 std::cout << "Nanosecond part: " << ns_of_sec() << '\n';
21 std::cout << "Microsecond part: " << us_of_sec() << '\n';
22 std::cout << "Millisecond part: " << ms_of_sec() << '\n';
23
24 std::cout << "CPU time used: " << get_cpu_time() << " s" << '\n';
25 std::cout << "Realtime (us): " << now_realtime_us() << '\n';
26
27 std::cout << "Press Enter to exit..." << std::endl;
28 std::cin.get();
29 return 0;
30}
TIME_SHIELD_CONSTEXPR ts_t ts(year_t year, int month, int day)
Alias for to_timestamp.
TIME_SHIELD_CONSTEXPR T ns_of_sec(fts_t ts) noexcept
Get the nanosecond part of the second from a floating-point timestamp.
TIME_SHIELD_CONSTEXPR ts_ms_t ts_ms(year_t year, int month, int day)
Alias for to_timestamp_ms.
TIME_SHIELD_CONSTEXPR T ms_of_sec(fts_t ts) noexcept
Get the millisecond part of the second from a floating-point timestamp.
TIME_SHIELD_CONSTEXPR T us_of_sec(fts_t ts) noexcept
Get the microsecond part of the second from a floating-point timestamp.
int64_t now_realtime_us()
Get current real time in microseconds using a platform-specific method.
double get_cpu_time() noexcept
Get the CPU time used by the current process.
ts_us_t ts_us() noexcept
Get the current UTC timestamp in microseconds.
Main namespace for the Time Shield library.
Header file with time-related utility functions.
int main()