Time Shield Library
C++ library for working with time
Toggle main menu visibility
Loading...
Searching...
No Matches
time_utils_example.cpp
Go to the documentation of this file.
1
6
7
#include <iostream>
8
9
#include <
time_shield/time_utils.hpp
>
10
11
int
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::ts
TIME_SHIELD_CONSTEXPR ts_t ts(year_t year, int month, int day)
Alias for to_timestamp.
Definition
time_conversion_aliases.hpp:363
time_shield::ns_of_sec
TIME_SHIELD_CONSTEXPR T ns_of_sec(fts_t ts) noexcept
Get the nanosecond part of the second from a floating-point timestamp.
Definition
time_unit_conversions.hpp:27
time_shield::ts_ms
TIME_SHIELD_CONSTEXPR ts_ms_t ts_ms(year_t year, int month, int day)
Alias for to_timestamp_ms.
Definition
time_conversion_aliases.hpp:855
time_shield::ms_of_sec
TIME_SHIELD_CONSTEXPR T ms_of_sec(fts_t ts) noexcept
Get the millisecond part of the second from a floating-point timestamp.
Definition
time_unit_conversions.hpp:47
time_shield::us_of_sec
TIME_SHIELD_CONSTEXPR T us_of_sec(fts_t ts) noexcept
Get the microsecond part of the second from a floating-point timestamp.
Definition
time_unit_conversions.hpp:37
time_shield::now_realtime_us
int64_t now_realtime_us()
Get current real time in microseconds using a platform-specific method.
Definition
time_utils.hpp:61
time_shield::get_cpu_time
double get_cpu_time() noexcept
Get the CPU time used by the current process.
Definition
time_utils.hpp:284
time_shield::ts_us
ts_us_t ts_us() noexcept
Get the current UTC timestamp in microseconds.
Definition
time_utils.hpp:266
time_shield
Main namespace for the Time Shield library.
time_utils.hpp
Header file with time-related utility functions.
main
int main()
Definition
time_utils_example.cpp:11
examples
time_utils_example.cpp
Generated by
1.17.0