A simple, feature-rich modern C++ date-time class.
More...
#include <datetime.h>
|
| datetime (uint64_t ms) |
| Construct a new datetime object.
|
|
| datetime (const datetime &other) |
| Construct a new datetime object.
|
|
| ~datetime () |
| Destroy the datetime object.
|
|
uint64_t | timestamp () const |
| Get the timestamp in milliseconds.
|
|
std::string | format (datetime_format dfmt=datetime_format::datetime_format_a, bool local=true, bool show_milliseconds=true) const |
| format the datetime object to a string
|
|
std::string | format (const std::string &fmt, bool local=true, bool show_milliseconds=true) const |
| Format the datetime object to a string with a custom format string.
|
|
std::string | utctime () const |
| Get the string of UTC time described by datetime object.
|
|
datetime & | operator= (const datetime &other) |
| Define the assignment operator.
|
|
datetime | operator+ (uint64_t ms) |
| Define the addition operator.
|
|
datetime | operator- (uint64_t ms) |
| Define the subtraction operator.
|
|
datetime & | operator+= (uint64_t ms) |
| Define the addition and assignment operator.
|
|
datetime & | operator-= (uint64_t ms) |
| Define the subtraction and assignment operator.
|
|
int64_t | operator- (const datetime &other) const |
| Define the subtraction operator between two datetime objects.
|
|
|
static datetime | now () |
| Get a datetime object for the current system time.
|
|
static datetime | get (const std::string &time_text, int isdst=-1) |
| Constructs a datetime object from a local time string.
|
|
|
static constexpr int | second = 1000 |
| Constants value: second, expressed in milliseconds.
|
|
static constexpr int | min = 60 * second |
| Constants value: min, expressed in milliseconds.
|
|
static constexpr int | hour = 60 * min |
| Constants value: hour, expressed in milliseconds.
|
|
static constexpr int | day = 24 * hour |
| Constants value: day, expressed in milliseconds.
|
|
A simple, feature-rich modern C++ date-time class.
◆ datetime() [1/2]
cutl::datetime::datetime |
( |
uint64_t | ms | ) |
|
Construct a new datetime object.
- Parameters
-
ms | a timestamp in milliseconds for initialize the datetime object |
◆ datetime() [2/2]
cutl::datetime::datetime |
( |
const datetime & | other | ) |
|
Construct a new datetime object.
- Parameters
-
other | other datetime object to copy |
◆ format() [1/2]
std::string cutl::datetime::format |
( |
const std::string & | fmt, |
|
|
bool | local = true, |
|
|
bool | show_milliseconds = true ) const |
Format the datetime object to a string with a custom format string.
- Parameters
-
fmt | datetime format string, default is "%Y-%m-%d %H:%M:%S.%f". usages like std::put_time, reference to https://en.cppreference.com/w/cpp/io/manip/put_time |
local | whether to use local time, default is true. if true means output in local time, otherwise, output in UTC time. |
show_milliseconds | whether to show milliseconds, default is true. if true means show milliseconds, otherwise, not show milliseconds. |
- Returns
- formatted datetime string described by std::string
◆ format() [2/2]
format the datetime object to a string
- Parameters
-
dfmt | datetime format, a value of datetime_format enum, default is datetime_format_a |
local | whether to use local time, default is true. if true means output in local time, otherwise, output in UTC time. |
show_milliseconds | whether to show milliseconds, default is true. if true means show milliseconds, otherwise, not show milliseconds. |
- Returns
- formatted datetime string described by std::string
◆ get()
static datetime cutl::datetime::get |
( |
const std::string & | time_text, |
|
|
int | isdst = -1 ) |
|
static |
Constructs a datetime object from a local time string.
Only the following time formats are supported:
- YYYY-MM-DD HH:MM:SS.sss
- YYYY-MM-DD HH:MM:SS
- YYYY.MM.DD HH:MM:SS.sss
- YYYY.MM.DD HH:MM:SS
- YYYY/MM/DD HH:MM:SS.sss
- YYYY/MM/DD HH:MM:SS
- YYYYMMDD HH:MM:SS.sss
- YYYYMMDD HH:MM:SS
- Parameters
-
time_text | local time string, use the below formats to construct a datetime object. |
isdst | the setting of daylight saving time, -1 means system automatically determine, 0 means not in daylight saving time, 1 means in daylight saving time |
- Returns
- datetime object constructed from the local time string
◆ now()
Get a datetime object for the current system time.
- Returns
- datetime object for the current system time
◆ operator+()
datetime cutl::datetime::operator+ |
( |
uint64_t | ms | ) |
|
Define the addition operator.
- Parameters
-
- Returns
- datetime object after adding milliseconds
◆ operator+=()
datetime & cutl::datetime::operator+= |
( |
uint64_t | ms | ) |
|
Define the addition and assignment operator.
- Parameters
-
- Returns
- datetime& the reference of the current datetime object after adding milliseconds
◆ operator-() [1/2]
int64_t cutl::datetime::operator- |
( |
const datetime & | other | ) |
const |
Define the subtraction operator between two datetime objects.
- Parameters
-
other | datetime object to subtract |
- Returns
- the duration in milliseconds between current and other datetime objects
◆ operator-() [2/2]
datetime cutl::datetime::operator- |
( |
uint64_t | ms | ) |
|
Define the subtraction operator.
- Parameters
-
ms | milliseconds to subtract |
- Returns
- datetime object after subtracting milliseconds
◆ operator-=()
datetime & cutl::datetime::operator-= |
( |
uint64_t | ms | ) |
|
Define the subtraction and assignment operator.
- Parameters
-
ms | milliseconds to subtract |
- Returns
- datetime& the reference of the current datetime object after subtracting milliseconds
◆ operator=()
Define the assignment operator.
- Parameters
-
other | other datetime object to copy |
- Returns
- datetime& the reference of the current datetime object
◆ timestamp()
uint64_t cutl::datetime::timestamp |
( |
| ) |
const |
Get the timestamp in milliseconds.
- Returns
- the timestamp in milliseconds
◆ utctime()
std::string cutl::datetime::utctime |
( |
| ) |
const |
|
inline |
Get the string of UTC time described by datetime object.
- Returns
- the string of UTC time in format "YYYY-MM-DD HH:MM:SS.sss"
The documentation for this class was generated from the following file: