CppCommon  1.0.4.1
C++ Common Library
time_timestamp.cpp

Timestamp example

#include "time/timestamp.h"
#include <iostream>
#include <thread>
void show(const CppCommon::Timestamp& timestamp)
{
std::cout << "Timestamp.days() = " << timestamp.days() << std::endl;
std::cout << "Timestamp.hours() = " << (timestamp.hours() % 24) << std::endl;
std::cout << "Timestamp.minutes() = " << (timestamp.minutes() % 60) << std::endl;
std::cout << "Timestamp.seconds() = " << (timestamp.seconds() % 60) << std::endl;
std::cout << "Timestamp.milliseconds() = " << (timestamp.milliseconds() % 1000) << std::endl;
std::cout << std::endl;
}
int main(int argc, char** argv)
{
for (int i = 0; i < 10; ++i)
{
std::cout << "UTC value: " << CppCommon::Timestamp::utc() << std::endl;
std::cout << "Local value: " << CppCommon::Timestamp::local() << std::endl;
std::cout << "Nano value: " << CppCommon::Timestamp::nano() << std::endl;
std::cout << "RDTS value: " << CppCommon::Timestamp::rdts() << std::endl;
std::this_thread::yield();
}
std::cout << std::endl;
std::cout << "Epoch timestamp:" << std::endl;
std::cout << "UTC timestamp:" << std::endl;
std::cout << "Local timestamp:" << std::endl;
std::cout << "Nano timestamp:" << std::endl;
std::cout << "RDTS timestamp:" << std::endl;
return 0;
}
Epoch timestamp.
Definition: timestamp.h:236
Local timestamp.
Definition: timestamp.h:260
High resolution timestamp.
Definition: timestamp.h:272
RDTS timestamp.
Definition: timestamp.h:284
uint64_t minutes() const noexcept
Get total minutes of the current timestamp.
Definition: timestamp.h:140
static uint64_t local()
Get the local timestamp.
Definition: timestamp.cpp:123
uint64_t milliseconds() const noexcept
Get total milliseconds of the current timestamp.
Definition: timestamp.h:146
static uint64_t utc()
Get the UTC timestamp.
Definition: timestamp.cpp:105
static uint64_t nano()
Get the high resolution timestamp.
Definition: timestamp.cpp:153
uint64_t seconds() const noexcept
Get total seconds of the current timestamp.
Definition: timestamp.h:143
static uint64_t rdts()
Get the current value of RDTS (Read Time Stamp Counter)
Definition: timestamp.cpp:205
uint64_t hours() const noexcept
Get total hours of the current timestamp.
Definition: timestamp.h:137
uint64_t days() const noexcept
Get total days of the current timestamp.
Definition: timestamp.h:134
UTC timestamp.
Definition: timestamp.h:248
Timestamp definition.