FDateTime

Implements a date and time.

Windows
MacOS
Linux

References

Module

Core

Header

/Engine/Source/Runtime/Core/Public/Misc/DateTime.h

Include

#include "Misc/DateTime.h"

Syntax

struct FDateTime

Remarks

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.

Constructors

Name Description

Public function

FDateTime()

Default constructor (no initialization).

Public function

FDateTime

(
    int64 InTicks
)

Creates and initializes a new instance with the specified number of ticks.

Public function

FDateTime

(
    int32 Year,
    int32 Month,
    int32 Day,
    int32 Hour,
    int32 Minute,
    int32 Second,
    int32 Millisecond
)

Creates and initializes a new instance with the specified year, month, day, hour, minute, second and millisecond.

Functions

Name Description

Public function Static

int32

 

DaysInMonth

(
    int32 Year,
    int32 Month
)

Gets the number of days in the year and month.

Public function Static

int32

 

DaysInYear

(
    int32 Year
)

Gets the number of days in the given year.

Public function Const

bool

 

ExportTextItem

(
    FString& ValueStr,
    FDateTime const& DefaultValue,
    UObject* Parent,
    int32 PortFlags,
    UObject* ExportRootScope
)

Exports the date and time value to a string.

Public function Static

FDateTime

 

FromJulianDay

(
    double JulianDay
)

Returns the proleptic Gregorian date for the given Julian Day.

Public function Static

FDateTime

 

FromUnixTimestamp

(
    int64 UnixTime
)

Returns the date from Unix time (seconds from midnight 1970-01-01)

Public function Const

FDateTime

 

GetDate()

Gets the date part of this date.

The time part is truncated and becomes 00:00:00.000.

Public function Const

void

 

GetDate

(
    int32& OutYear,
    int32& OutMonth,
    int32& OutDay
)

Gets the date components of this date.

Public function Const

int32

 

GetDay()

Gets this date's day part (1 to 31).

Public function Const

EDayOfWeek

 

GetDayOfWeek()

Calculates this date's day of the week (Sunday - Saturday).

Public function Const

int32

 

GetDayOfYear()

Gets this date's day of the year.

Public function Const

int32

 

GetHour()

Gets this date's hour part in 24-hour clock format (0 to 23).

Public function Const

int32

 

GetHour12()

Gets this date's hour part in 12-hour clock format (1 to 12).

Public function Const

double

 

GetJulianDay()

Returns the Julian Day for this date.

Public function Const

int32

 

GetMillisecond()

Gets this date's millisecond part (0 to 999).

Public function Const

int32

 

GetMinute()

Gets this date's minute part (0 to 59).

Public function Const

double

 

GetModifiedJulianDay()

Returns the Modified Julian day.

Public function Const

int32

 

GetMonth()

Gets this date's the month part (1 to 12).

Public function Const

EMonthOfYear

 

GetMonthOfYear()

Gets the date's month of the year (January to December).

Public function Const

int32

 

GetSecond()

Gets this date's second part.

Public function Const

int64

 

GetTicks()

Gets this date's representation as number of ticks.

Public function Const

FTimespan

 

GetTimeOfDay()

Gets the time elapsed since midnight of this date.

Public function Const

int32

 

GetYear()

Gets this date's year part.

Public function

bool

 

ImportTextItem

(
    const TCHAR*& Buffer,
    int32 PortFlags,
    UObject* Parent,
    FOutputDevice* ErrorText
)

Imports a date and time value from a text buffer.

Public function Const

bool

 

IsAfternoon()

Gets whether this date's time is in the afternoon.

Public function Static

bool

 

IsLeapYear

(
    int32 Year
)

Checks whether the given year is a leap year.

Public function Const

bool

 

IsMorning()

Gets whether this date's time is in the morning.

Public function Static

FDateTime

 

MaxValue()

Returns the maximum date value.

The maximum date value is December 31, 9999, 23:59:59.9999999.

Public function Static

FDateTime

 

MinValue()

Returns the minimum date value.

The minimum date value is January 1, 0001, 00:00:00.0.

Public function

bool

 

NetSerialize

(
    FArchive& Ar,
    UPackageMap* Map,
    bool& bOutSuccess
)

Serializes this date and time for network transmission

Public function Static

FDateTime

 

Now()

Gets the local date and time on this computer.

Public function Static

bool

 

Parse

(
    const FString& DateTimeString,
    FDateTime& OutDateTime
)

Converts a string to a date and time.

Public function Static

bool

 

ParseHttpDate

(
    const FString& HttpDate,
    FDateTime& OutDateTime
)

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

Public function Static

bool

 

ParseIso8601

(
    const TCHAR* DateTimeString,
    FDateTime& OutDateTime
)

Parses a date string in ISO-8601 format.

Public function

bool

 

Serialize

(
    FArchive& Ar
)

Serializes this date and time from or into the specified archive.

Public function Static

FDateTime

 

Today()

Gets the local date on this computer.

The time component is set to 00:00:00

Public function Const

FString

 

ToHttpDate()

Returns the RFC 1123 string representation of the FDateTime.

Public function Const

FString

 

ToIso8601()

Returns the ISO-8601 string representation of the FDateTime.

Public function Const

FString

 

ToString()

Returns the string representation of this date using a default format.

Public function Const

FString

 

ToString

(
    const TCHAR* Format
)

Returns the string representation of this date.

Public function Const

int64

 

ToUnixTimestamp()

Returns this date as the number of seconds since the Unix Epoch (January 1st of 1970).

Public function Static

FDateTime

 

UtcNow()

Gets the UTC date and time on this computer.

Public function Static

bool

 

Validate

(
    int32 Year,
    int32 Month,
    int32 Day,
    int32 Hour,
    int32 Minute,
    int32 Second,
    int32 Millisecond
)

Validates the given components of a date and time value.

Operators

Name Description

Public function Const

FDateTime

 

operator-

(
    const FTimespan& Other
)

Returns result of subtracting the given time span from this date.

Public function Const

FTimespan

 

operator-

(
    const FDateTime& Other
)

Returns time span between this date and the given date.

Public function Const

bool

 

operator!=

(
    const FDateTime& Other
)

Compares this date with the given date for inequality.

Public function

FDateTime &

 

operator+

(
    const FDateTime& Other
)

Adds the time from the given date to this date.

Public function Const

FDateTime

 

operator+

(
    const FTimespan& Other
)

Returns result of adding the given time span to this date.

Public function

FDateTime &

 

operator+=

(
    const FTimespan& Other
)

Adds the given time span to this date.

Public function Const

bool

 

operator<

(
    const FDateTime& Other
)

Checks whether this date is less than the given date.

Public function Const

bool

 

operator<=

(
    const FDateTime& Other
)

Checks whether this date is less than or equal to the given date.

Public function

FDateTime &

 

operator-=

(
    const FTimespan& Other
)

Subtracts the given time span from this date.

Public function Const

bool

 

operator==

(
    const FDateTime& Other
)

Compares this date with the given date for equality.

Public function Const

bool

 

operator>

(
    const FDateTime& Other
)

Checks whether this date is greater than the given date.

Public function Const

bool

 

operator>=

(
    const FDateTime& Other
)

Checks whether this date is greater than or equal to the date span.

Constants

Name

Description

DaysPerMonth

Holds the days per month in a non-leap year.

DaysToMonth

Holds the cumulative days per month in a non-leap year.

See Also

Help shape the future of Unreal Engine documentation! Tell us how we're doing so we can serve you better.
Take our survey
Dismiss