|
trantor
Non-blocking I/O cross-platform TCP network library, using C++14
|
This class represents a time point. More...
#include <trantor/utils/Date.h>
Public Member Functions | |
| Date (int64_t microSec) | |
| Construct a new Date instance. | |
| Date (unsigned int year, unsigned int month, unsigned int day, unsigned int hour=0, unsigned int minute=0, unsigned int second=0, unsigned int microSecond=0) | |
| Construct a new Date instance. | |
| const Date | after (double second) const |
| Return a new Date instance that represents the time after some seconds from *this. | |
| const Date | roundSecond () const |
| Return a new Date instance that equals to *this, but with zero microseconds. | |
| const Date | roundDay () const |
| Return a new Date instance that equals to * this, but with zero hours, minutes, seconds and microseconds. | |
| bool | operator== (const Date &date) const |
| Return true if the time point is equal to another. | |
| bool | operator!= (const Date &date) const |
| Return true if the time point is not equal to another. | |
| bool | operator< (const Date &date) const |
| Return true if the time point is earlier than another. | |
| bool | operator> (const Date &date) const |
| Return true if the time point is later than another. | |
| bool | operator>= (const Date &date) const |
| Return true if the time point is not earlier than another. | |
| bool | operator<= (const Date &date) const |
| Return true if the time point is not later than another. | |
| int64_t | microSecondsSinceEpoch () const |
| Get the number of milliseconds since 1970-01-01 00:00. | |
| int64_t | secondsSinceEpoch () const |
| Get the number of seconds since 1970-01-01 00:00. | |
| struct tm | tmStruct () const |
| Get the tm struct for the time point. | |
| std::string | toFormattedString (bool showMicroseconds) const |
| Generate a UTC time string. | |
| std::string | toCustomedFormattedString (const std::string &fmtStr, bool showMicroseconds=false) const |
Generate a UTC time string formatted by the fmtStr. | |
| std::string | toCustomFormattedString (const std::string &fmtStr, bool showMicroseconds=false) const |
Generate a UTC time string formatted by the fmtStr. | |
| std::string | toFormattedStringLocal (bool showMicroseconds) const |
| Generate a local time zone string, the format of the string is same as the method toFormattedString. | |
| std::string | toCustomedFormattedStringLocal (const std::string &fmtStr, bool showMicroseconds=false) const |
Generate a local time zone string formatted by the fmtStr. | |
| std::string | toCustomFormattedStringLocal (const std::string &fmtStr, bool showMicroseconds=false) const |
Generate a local time zone string formatted by the fmtStr. | |
| std::string | toDbStringLocal () const |
| Generate a local time zone string for database. | |
| std::string | toDbString () const |
| Generate a UTC time string for database. | |
| void | toCustomedFormattedString (const std::string &fmtStr, char *str, size_t len) const |
| Generate a UTC time string. | |
| void | toCustomFormattedString (const std::string &fmtStr, char *str, size_t len) const |
| Generate a UTC time string. | |
| bool | isSameSecond (const Date &date) const |
| Return true if the time point is in a same second as another. | |
| void | swap (Date &that) |
| Swap the time point with another. | |
Static Public Member Functions | |
| static const Date | date () |
| Create a Date object that represents the current time. | |
| static const Date | now () |
| Same as the date() method. | |
| static int64_t | timezoneOffset () |
| static Date | fromDbStringLocal (const std::string &datetime) |
| From DB string to trantor local time zone. | |
| static Date | fromDbString (const std::string &datetime) |
| From DB string to trantor UTC time. | |
| static Date | fromISOString (const std::string &datetime) |
| Parse a datetime string in ISO-8601 format with some flexibility. Accepts the following formats: | |
Static Public Attributes | |
| static constexpr long | MICRO_SECONDS_PER_SEC = 1000000LL |
This class represents a time point.
|
inlineexplicit |
Construct a new Date instance.
| microSec | The microseconds from 1970-01-01 00:00:00. |
| trantor::Date::Date | ( | unsigned int | year, |
| unsigned int | month, | ||
| unsigned int | day, | ||
| unsigned int | hour = 0, | ||
| unsigned int | minute = 0, | ||
| unsigned int | second = 0, | ||
| unsigned int | microSecond = 0 ) |
Construct a new Date instance.
| year | |
| month | |
| day | |
| hour | |
| minute | |
| second | |
| microSecond |
| const Date trantor::Date::after | ( | double | second | ) | const |
|
static |
|
static |
From DB string to trantor UTC time.
Inverse of toDbString()
|
static |
From DB string to trantor local time zone.
Inverse of toDbStringLocal()
|
static |
Parse a datetime string in ISO-8601 format with some flexibility. Accepts the following formats:
|
inline |
Return true if the time point is in a same second as another.
| date |
|
inline |
Get the number of milliseconds since 1970-01-01 00:00.
| const Date trantor::Date::roundDay | ( | ) | const |
| const Date trantor::Date::roundSecond | ( | ) | const |
|
inline |
Get the number of seconds since 1970-01-01 00:00.
|
inline |
Swap the time point with another.
| that |
| struct tm trantor::Date::tmStruct | ( | ) | const |
Get the tm struct for the time point.
|
inline |
Generate a UTC time string formatted by the fmtStr.
| fmtStr | is the format string for the function strftime() |
| showMicroseconds | whether the microseconds are returned. |
fmtStr is "%Y-%m-%d %H:%M:%S" and the showMicroseconds is falsefmtStr is "%Y-%m-%d %H:%M:%S" and the showMicroseconds is true
|
inline |
Generate a UTC time string.
| fmtStr | The format string. |
| str | The string buffer for the generated time string. |
| len | The length of the string buffer. |
|
inline |
Generate a local time zone string formatted by the fmtStr.
| fmtStr | |
| showMicroseconds |
| std::string trantor::Date::toCustomFormattedString | ( | const std::string & | fmtStr, |
| bool | showMicroseconds = false ) const |
Generate a UTC time string formatted by the fmtStr.
| fmtStr | is the format string for the function strftime() |
| showMicroseconds | whether the microseconds are returned. |
fmtStr is "%Y-%m-%d %H:%M:%S" and the showMicroseconds is falsefmtStr is "%Y-%m-%d %H:%M:%S" and the showMicroseconds is true | void trantor::Date::toCustomFormattedString | ( | const std::string & | fmtStr, |
| char * | str, | ||
| size_t | len ) const |
Generate a UTC time string.
| fmtStr | The format string. |
| str | The string buffer for the generated time string. |
| len | The length of the string buffer. |
| std::string trantor::Date::toCustomFormattedStringLocal | ( | const std::string & | fmtStr, |
| bool | showMicroseconds = false ) const |
Generate a local time zone string formatted by the fmtStr.
| fmtStr | |
| showMicroseconds |
| std::string trantor::Date::toDbStringLocal | ( | ) | const |
Generate a local time zone string for database.
| std::string trantor::Date::toFormattedString | ( | bool | showMicroseconds | ) | const |
Generate a UTC time string.
| showMicroseconds | whether the microseconds are returned. |
showMicroseconds is falseshowMicroseconds is true | std::string trantor::Date::toFormattedStringLocal | ( | bool | showMicroseconds | ) | const |
Generate a local time zone string, the format of the string is same as the method toFormattedString.
| showMicroseconds |