122 static datetime get(
const std::string &time_text,
int isdst = -1);
139 std::string
format(
datetime_format dfmt = datetime_format::datetime_format_a,
bool local =
true,
bool show_milliseconds =
true)
const;
150 std::string
format(
const std::string &fmt,
bool local =
true,
bool show_milliseconds =
true)
const;
159 return format(datetime_format::datetime_format_a,
false);
211 using time_regex_type = std::pair<std::string, std::regex>;
212 using time_regex_vec_type = std::vector<time_regex_type>;
213 static std::string supported_time_formats(
const time_regex_vec_type &fmtlist);
214 static bool verify_time(
const struct tm &time);
217 uint64_t timestamp_ms_;
A simple, feature-rich modern C++ date-time class.
Definition datetime.h:51
static constexpr int hour
Constants value: hour, expressed in milliseconds.
Definition datetime.h:67
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.
static constexpr int min
Constants value: min, expressed in milliseconds.
Definition datetime.h:62
static datetime now()
Get a datetime object for the current system time.
std::string utctime() const
Get the string of UTC time described by datetime object.
Definition datetime.h:157
static constexpr int day
Constants value: day, expressed in milliseconds.
Definition datetime.h:72
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
datetime & operator-=(uint64_t ms)
Define the subtraction and assignment operator.
uint64_t timestamp() const
Get the timestamp in milliseconds.
~datetime()
Destroy the datetime object.
datetime operator+(uint64_t ms)
Define the addition operator.
datetime & operator=(const datetime &other)
Define the assignment operator.
datetime(const datetime &other)
Construct a new datetime object.
datetime operator-(uint64_t ms)
Define the subtraction operator.
datetime(uint64_t ms)
Construct a new datetime object.
datetime & operator+=(uint64_t ms)
Define the addition and assignment operator.
static constexpr int second
Constants value: second, expressed in milliseconds.
Definition datetime.h:57
static datetime get(const std::string &time_text, int isdst=-1)
Constructs a datetime object from a local time string.
int64_t operator-(const datetime &other) const
Define the subtraction operator between two datetime objects.
datetime_format
the string datetime format for parsing and formatting
Definition datetime.h:35
std::ostream & operator<<(std::ostream &os, const datetime &dt)
Define the output stream operator for datetime object.