DateTime class
#include <Containers/DateTime.h>
Instant in time, typically expressed as a date and time of day.
Public types
- class TimeZone
- Represents a timezone that can be used in timezone conversions in DateTime.
- struct Tm
- Describes a date and time represented by DateTime.
- enum Tz { Local, GMT_12, GMT_11, GMT_10, GMT_9, GMT_8, GMT_7, GMT_6, GMT_5, GMT_4, GMT_3, GMT_2, GMT_1, GMT0, GMT1, GMT2, GMT3, GMT4, GMT5, GMT6, GMT7, GMT8, GMT9, GMT10, GMT11, GMT12, GMT13, UTC = GMT0, WET = GMT0, WEST = GMT1, CET = GMT1, CEST = GMT2, EET = GMT2, EEST = GMT3, MSK = GMT3, MSD = GMT4, AST = GMT_4, ADT = GMT_3, EST = GMT_5, EDT = GMT_4, CST = GMT_6, CDT = GMT_5, MST = GMT_7, MDT = GMT_6, PST = GMT_8, PDT = GMT_7, HST = GMT_10, AKST = GMT_9, AKDT = GMT_8, A_WST = GMT8, A_CST = GMT13 + 1, A_EST = GMT10, A_ESST = GMT11, NZST = GMT12, NZDT = GMT13 }
- Well-known timezones.
Public static functions
- static auto UtcNow() -> DateTime noexcept
- Returns DateTime that is set to the current date and time on this computer, expressed as the UTC time.
-
static auto FromUnixMilliseconds(std::
int64_t value) -> DateTime constexpr noexcept - Returns DateTime created from number of milliseconds since 00:00, Jan 1 1970 UTC.
Constructors, destructors, conversion operators
- DateTime() constexpr noexcept
- Creates invalid DateTime structure.
- DateTime(NoInitT) explicit noexcept
- Creates uninitialized DateTime structure.
- DateTime(time_t timet) constexpr noexcept
- Creates DateTime structure from standard
time_tvalue. - DateTime(const struct tm& tm) noexcept
- Creates DateTime structure from standard
tmstructure. - DateTime(const Tm& tm) noexcept
- Creates DateTime structure from partitioned DateTime.
-
DateTime(std::
int32_t year, std:: int32_t month, std:: int32_t day, std:: int32_t hour = 0, std:: int32_t minute = 0, std:: int32_t second = 0, std:: int32_t milliseconds = 0) noexcept - Creates DateTime structure from individual parts.
- DateTime(const SYSTEMTIME& st) noexcept
- Creates DateTime structure from Windows®
SYSTEMTIMEstructure. - DateTime(const FILETIME& st) noexcept
- Creates DateTime structure from Windows®
FILETIMEstructure. - operator bool() const explicit noexcept
Public functions
-
auto GetYear(TimeZone tz = Local) const -> std::
int32_t noexcept - Returns the year component of the date represented by this instance.
-
auto GetMonth(TimeZone tz = Local) const -> std::
int32_t noexcept - Returns the month component of the date represented by this instance.
-
auto GetDay(TimeZone tz = Local) const -> std::
int32_t noexcept - Returns the day of the month represented by this instance.
-
auto GetWeekDay(TimeZone tz = Local) const -> std::
int32_t noexcept - Returns the day of the week represented by this instance.
-
auto GetHour(TimeZone tz = Local) const -> std::
int32_t noexcept - Returns the hour component of the date represented by this instance.
-
auto GetMinute(TimeZone tz = Local) const -> std::
int32_t noexcept - Returns the minute component of the date represented by this instance.
-
auto GetSecond(TimeZone tz = Local) const -> std::
int32_t noexcept - Returns the second component of the date represented by this instance.
-
auto GetMillisecond(TimeZone tz = Local) const -> std::
int32_t noexcept - Returns the millisecond component of the date represented by this instance.
- auto Set(time_t timet) -> DateTime& constexpr noexcept
- Sets DateTime structure to the value corresponding to standard
time_tvalue. - auto Set(const struct tm& tm) -> DateTime& noexcept
- Sets DateTime structure to the value corresponding to standard
tmstructure. - auto Set(const Tm& tm) -> DateTime& noexcept
- Sets DateTime structure to the value corresponding to partitioned DateTime.
-
auto Set(std::
int32_t year, std:: int32_t month, std:: int32_t day, std:: int32_t hour = 0, std:: int32_t minute = 0, std:: int32_t second = 0, std:: int32_t millisec = 0) -> DateTime& noexcept - Sets DateTime structure from individual parts.
-
auto SetYear(std::
int32_t year) -> DateTime& noexcept - Sets the year component of the date represented by this instance.
-
auto SetMonth(std::
int32_t month) -> DateTime& noexcept - Sets the month component of the date represented by this instance.
-
auto SetDay(std::
int32_t day) -> DateTime& noexcept - Sets the day of the month represented by this instance.
-
auto SetHour(std::
int32_t hour) -> DateTime& noexcept - Sets the hour component of the date represented by this instance.
-
auto SetMinute(std::
int32_t minute) -> DateTime& noexcept - Sets the minute component of the date represented by this instance.
-
auto SetSecond(std::
int32_t second) -> DateTime& noexcept - Sets the second component of the date represented by this instance.
-
auto SetMillisecond(std::
int32_t millisecond) -> DateTime& noexcept - Sets the millisecond component of the date represented by this instance.
- auto ResetTime() -> DateTime& noexcept
- Resets the time component of the date represented by this instance to 0:00:00.
- auto IsValid() const -> bool constexpr noexcept
- auto Partitioned(TimeZone tz = Local) const -> Tm noexcept
- Returns DateTime structure partitioned into individual components.
-
auto ToUnixMilliseconds() const -> std::
int64_t constexpr noexcept - Returns number of milliseconds since 00:00, Jan 1 1970 UTC.
- auto GetTicks() const -> time_t constexpr noexcept
- Returns number of seconds since 00:00, Jan 1 1970 UTC.
- auto ToTimezone(TimeZone tz, bool noDST = false) const -> DateTime noexcept
- Creates a new DateTime structure moved from the local timezone to a given timezone.
- auto FromTimezone(TimeZone tz, bool noDST = false) const -> DateTime noexcept
- Creates a new DateTime structure moved from a given timezone to the local timezone.
- void AdjustToTimezone(TimeZone tz, bool noDST = false) noexcept
- Moves DateTime structure from the local timezone to a given timezone.
- void AdjustFromTimezone(TimeZone tz, bool noDST = false) noexcept
- Moves DateTime structure from a given timezone to the local timezone.
- auto ToWin32() const -> SYSTEMTIME noexcept
- Returns DateTime structure converted to Windows®
SYSTEMTIMEstructure to be passed to Windows APIs. - auto TryParse(StringView input, StringView format, StringView* endParse = nullptr) -> bool noexcept
- Converts the specified string representation of a date and time to its DateTime equivalent.
- auto ToString() const -> String noexcept
- Converts this instance to the string representation.
- auto operator+=(const TimeSpan& ts) -> DateTime& constexpr noexcept
- auto operator+(const TimeSpan& ts) const -> DateTime constexpr noexcept
- auto operator-=(const TimeSpan& ts) -> DateTime& constexpr noexcept
- auto operator-(const TimeSpan& ts) const -> DateTime constexpr noexcept
- auto operator-(const DateTime& dt) const -> TimeSpan constexpr noexcept
- auto operator<(const DateTime& dt) const -> bool constexpr noexcept
- auto operator<=(const DateTime& dt) const -> bool constexpr noexcept
- auto operator>(const DateTime& dt) const -> bool constexpr noexcept
- auto operator>=(const DateTime& dt) const -> bool constexpr noexcept
- auto operator==(const DateTime& dt) const -> bool constexpr noexcept
- auto operator!=(const DateTime& dt) const -> bool constexpr noexcept
Enum documentation
enum Death:: Containers:: DateTime:: Tz
Well-known timezones.
| Enumerators | |
|---|---|
| Local |
Specifies time in the current timezone. |
| GMT_12 |
|
| GMT_11 |
|
| GMT_10 |
|
| GMT_9 |
|
| GMT_8 |
|
| GMT_7 |
|
| GMT_6 |
|
| GMT_5 |
|
| GMT_4 |
|
| GMT_3 |
|
| GMT_2 |
|
| GMT_1 |
|
| GMT0 |
|
| GMT1 |
|
| GMT2 |
|
| GMT3 |
|
| GMT4 |
|
| GMT5 |
|
| GMT6 |
|
| GMT7 |
|
| GMT8 |
|
| GMT9 |
|
| GMT10 |
|
| GMT11 |
|
| GMT12 |
|
| GMT13 |
|
| UTC |
|
| WET |
|
| WEST |
|
| CET |
|
| CEST |
|
| EET |
|
| EEST |
|
| MSK |
|
| MSD |
|
| AST |
|
| ADT |
|
| EST |
|
| EDT |
|
| CST |
|
| CDT |
|
| MST |
|
| MDT |
|
| PST |
|
| PDT |
|
| HST |
|
| AKST |
|
| AKDT |
|
| A_WST |
|
| A_CST |
|
| A_EST |
|
| A_ESST |
|
| NZST |
|
| NZDT |
|
Function documentation
Death:: Containers:: DateTime:: DateTime(std:: int32_t year,
std:: int32_t month,
std:: int32_t day,
std:: int32_t hour = 0,
std:: int32_t minute = 0,
std:: int32_t second = 0,
std:: int32_t milliseconds = 0) noexcept
Creates DateTime structure from individual parts.
| Parameters | |
|---|---|
| year | Years |
| month | Months after the year (0-11) |
| day | Days after the month (1-31) |
| hour | Hours after the day (0-23) |
| minute | Minutes after the hour (0-59) |
| second | Seconds after the minute (0-59*) |
| milliseconds | Milliseconds after the second (0-999) |
DateTime& Death:: Containers:: DateTime:: Set(std:: int32_t year,
std:: int32_t month,
std:: int32_t day,
std:: int32_t hour = 0,
std:: int32_t minute = 0,
std:: int32_t second = 0,
std:: int32_t millisec = 0) noexcept
Sets DateTime structure from individual parts.
| Parameters | |
|---|---|
| year | Years |
| month | Months after the year (0-11) |
| day | Days after the month (1-31) |
| hour | Hours after the day (0-23) |
| minute | Minutes after the hour (0-59) |
| second | Seconds after the minute (0-59*) |
| millisec | Milliseconds after the second (0-999) |