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#if defined(_WIN32)
11#include <time_shield/types.hpp>
14
15int main() {
16 using namespace time_shield;
17
18 // Print different representations of the current time
19 std::cout << "Seconds since epoch: " << ts() << '\n';
20 std::cout << "Milliseconds since epoch: " << ts_ms() << '\n';
21 std::cout << "Microseconds since epoch: " << ts_us() << '\n';
22
23 // Show fractional parts of the current second
24 std::cout << "Nanosecond part: " << ns_of_sec() << '\n';
25 std::cout << "Microsecond part: " << us_of_sec() << '\n';
26 std::cout << "Millisecond part: " << ms_of_sec() << '\n';
27
28 std::cout << "CPU time used: " << get_cpu_time() << " s" << '\n';
29 std::cout << "Realtime (us) via QPC: " << now_realtime_us() << '\n';
30
31 std::cout << "Press Enter to exit..." << std::endl;
32 std::cin.get();
33 return 0;
34}
35#else
36int main() {
37 std::cout << "time_utils.hpp requires Windows for now_realtime_us()" << std::endl;
38 return 0;
39}
40#endif
Header file with time-related constants.
TIME_SHIELD_CONSTEXPR ts_t ts(year_t year, int month, int day)
Alias for to_timestamp.
constexpr const T ns_of_sec(fts_t ts) noexcept
Get the nanosecond part of the second from a floating-point timestamp.
constexpr ts_ms_t ts_ms(year_t year, int month, int day)
Alias for to_timestamp_ms.
constexpr const T ms_of_sec(fts_t ts) noexcept
Get the millisecond part of the second from a floating-point timestamp.
constexpr const 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 hybrid method.
double get_cpu_time() noexcept
Get the CPU time used by the current process.
const 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()
Type definitions for time-related units and formats.