Navigation
API > API/Runtime > API/Runtime/Core
Implements a date and time.
Values of this type represent dates and times between Midnight 00:00:00, January 1, 0001 and Midnight 23:59:59.9999999, December 31, 9999 in the Gregorian calendar. Internally, the time values are stored in ticks of 0.1 microseconds (= 100 nanoseconds) since January 1, 0001.
To retrieve the current local date and time, use the FDateTime.Now() method. To retrieve the current UTC time, use the FDateTime.UtcNow() method instead.
This class also provides methods to convert dates and times from and to string representations, calculate the number of days in a given month and year, check for leap years and determine the time of day, day of week and month of year of a given date and time.
The companion struct FTimespan is provided for enabling date and time based arithmetic, such as calculating the difference between two dates or adding a certain amount of time to a given date.
Ranges of dates and times can be represented by the FDateRange class.
| Name | FDateTime |
| Type | struct |
| Header File | /Engine/Source/Runtime/Core/Public/Misc/DateTime.h |
| Include Path | #include "Misc/DateTime.h" |
Syntax
struct FDateTime
Constructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
FDateTime
(
int32 Year, |
Creates and initializes a new instance with the specified year, month, day, hour, minute, second and millisecond. | Misc/DateTime.h | |
FDateTime
(
int64 InTicks |
Creates and initializes a new instance with the specified number of ticks. | Misc/DateTime.h | |
FDateTime () |
Default constructor (zero initialization). | Misc/DateTime.h |
Constants
| Name | Type | Remarks | Include Path |
|---|---|---|---|
| DaysPerMonth | const int32 | Holds the days per month in a non-leap year. | Misc/DateTime.h |
| DaysToMonth | const int32 | Holds the cumulative days per month in a non-leap year. | Misc/DateTime.h |
| LongDayNames | const TCHAR * | Misc/DateTime.h | |
| LongMonthNames | const TCHAR * | Misc/DateTime.h | |
| ShortDayNames | const TCHAR * | Holds the long and short day names. | Misc/DateTime.h |
| ShortMonthNames | const TCHAR * | Holds the long and short month names. | Misc/DateTime.h |
Variables
Protected
| Name | Type | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|---|
| Ticks | int64 | Holds the ticks in 100 nanoseconds resolution since January 1, 0001 A.D. | Misc/DateTime.h |
Functions
Public
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
bool ExportTextItem
(
FString& ValueStr, |
Exports the date and time value to a string. | Misc/DateTime.h | |
| Gets the date part of this date.The time part is truncated and becomes 00:00:00.000. | Misc/DateTime.h | ||
void GetDate
(
int32& OutYear, |
Gets the date components of this date. | Misc/DateTime.h | |
int32 GetDay () |
Gets this date's day part (1 to 31). | Misc/DateTime.h | |
| Calculates this date's day of the week (Sunday - Saturday). | Misc/DateTime.h | ||
int32 GetDayOfYear () |
Gets this date's day of the year. | Misc/DateTime.h | |
int32 GetHour () |
Gets this date's hour part in 24-hour clock format (0 to 23). | Misc/DateTime.h | |
int32 GetHour12 () |
Gets this date's hour part in 12-hour clock format (1 to 12). | Misc/DateTime.h | |
double GetJulianDay () |
Returns the Julian Day for this date. | Misc/DateTime.h | |
int32 GetMillisecond () |
Gets this date's millisecond part (0 to 999). | Misc/DateTime.h | |
int32 GetMinute () |
Gets this date's minute part (0 to 59). | Misc/DateTime.h | |
double GetModifiedJulianDay () |
Returns the Modified Julian day. | Misc/DateTime.h | |
int32 GetMonth () |
Gets this date's the month part (1 to 12). | Misc/DateTime.h | |
| Gets the date's month of the year (January to December). | Misc/DateTime.h | ||
int32 GetSecond () |
Gets this date's second part. | Misc/DateTime.h | |
int64 GetTicks() |
Gets this date's representation as number of ticks. | Misc/DateTime.h | |
| Gets the time elapsed since midnight of this date. | Misc/DateTime.h | ||
int32 GetYear () |
Gets this date's year part. | Misc/DateTime.h | |
bool ImportTextItem
(
const TCHAR*& Buffer, |
Imports a date and time value from a text buffer. | Misc/DateTime.h | |
bool IsAfternoon () |
Gets whether this date's time is in the afternoon. | Misc/DateTime.h | |
bool IsMorning () |
Gets whether this date's time is in the morning. | Misc/DateTime.h | |
bool NetSerialize
(
FArchive& Ar, |
Serializes this date and time for network transmission | Misc/DateTime.h | |
bool Serialize
(
FArchive& Ar |
Serializes this date and time from or into the specified archive. | Misc/DateTime.h | |
FString ToFormattedString
(
const TCHAR* Format |
Returns the string representation of this date. | Misc/DateTime.h | |
| Returns the RFC 1123 string representation of the FDateTime. | Misc/DateTime.h | ||
| Returns the ISO-8601 string representation of the FDateTime. | Misc/DateTime.h | ||
| Returns the string representation of this date. | Misc/DateTime.h | ||
| Returns the string representation of this date using a default format. | Misc/DateTime.h | ||
void ToString
(
const TCHAR* Format, |
Misc/DateTime.h | ||
int64 ToUnixTimestamp () |
Returns this date as the number of seconds since the Unix Epoch (January 1st of 1970). | Misc/DateTime.h | |
double ToUnixTimestampDecimal () |
Returns this date as the number of seconds since the Unix Epoch (January 1st of 1970). | Misc/DateTime.h |
Static
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
static int32 DaysInMonth
(
int32 Year, |
Gets the number of days in the year and month. | Misc/DateTime.h | |
static int32 DaysInYear
(
int32 Year |
Gets the number of days in the given year. | Misc/DateTime.h | |
static FDateTime FromJulianDay
(
double JulianDay |
Returns the proleptic Gregorian date for the given Julian Day. | Misc/DateTime.h | |
static FDateTime FromUnixTimestamp
(
int64 UnixTime |
Returns the date from Unix time (seconds from midnight 1970-01-01) | Misc/DateTime.h | |
static FDateTime FromUnixTimestampDecimal
(
double UnixTime |
Returns the date from Unix time (seconds from midnight 1970-01-01) | Misc/DateTime.h | |
static bool IsLeapYear
(
int32 Year |
Checks whether the given year is a leap year. | Misc/DateTime.h | |
| Returns the maximum date value.The maximum date value is December 31, 9999, 23:59:59.9999999. | Misc/DateTime.h | ||
| Returns the minimum date value.The minimum date value is January 1, 0001, 00:00:00.0. | Misc/DateTime.h | ||
| Gets the local date and time on this computer. | Misc/DateTime.h | ||
| Converts a string to a date and time. | Misc/DateTime.h | ||
static bool ParseHttpDate
(
const FString& HttpDate, |
Parses a date string in HTTP-date format (rfc1123-date | rfc850-date | asctime-date) https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1 | Misc/DateTime.h | |
static bool ParseIso8601
(
const TCHAR* DateTimeString, |
Parses a date string in ISO-8601 format. | Misc/DateTime.h | |
| Gets the local date on this computer.The time component is set to 00:00:00 | Misc/DateTime.h | ||
| Gets the UTC date and time on this computer. | Misc/DateTime.h | ||
static bool Validate
(
int32 Year, |
Validates the given components of a date and time value. | Misc/DateTime.h |
Operators
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
| Returns result of subtracting the given time span from this date. | Misc/DateTime.h | ||
| Returns time span between this date and the given date. | Misc/DateTime.h | ||
bool operator!=
(
const FDateTime& Other |
Compares this date with the given date for inequality. | Misc/DateTime.h | |
| Misc/DateTime.h | |||
| Returns result of adding the given time span to this date. | Misc/DateTime.h | ||
| Adds the given time span to this date. | Misc/DateTime.h | ||
| Subtracts the given time span from this date. | Misc/DateTime.h | ||
bool operator==
(
const FDateTime& Other |
Compares this date with the given date for equality. | Misc/DateTime.h | |
bool operator>
(
const FDateTime& Other |
Checks whether this date is greater than the given date. | Misc/DateTime.h | |
bool operator>=
(
const FDateTime& Other |
Checks whether this date is greater than or equal to the date span. | Misc/DateTime.h |