RealDocs

UKismetMathLibrary::GetTimeOfDay

function Engine Blueprint Since 4.0
#include "Kismet/KismetMathLibrary.h"
Access: public Specifiers: staticUFUNCTIONBlueprintPure

Description

Returns the time elapsed since midnight of the given date as an FTimespan in the range [0, 24 hours). Use this to strip the date portion and work with the time component alone.

Caveats & Gotchas

  • The result is always non-negative and less than 24 hours. Unlike GetDate which zeros the time, GetTimeOfDay zeros the date — combining both gives you back the full original value.
  • Comparing time-of-day values across day boundaries requires care: 23:59 is greater than 00:01 even though the latter is only 2 minutes into the next day. For window checks that span midnight (e.g. 23:00–01:00) you must handle the wraparound explicitly.

Signature

static UE_INL_API FTimespan GetTimeOfDay( FDateTime A );

Parameters

Name Type Description Default
A FDateTime The date-time to extract the time-of-day from.

Return Type

FTimespan

Example

Check if the current time is within a daily window C++
FDateTime Now = FDateTime::UtcNow();
FTimespan TimeNow = UKismetMathLibrary::GetTimeOfDay(Now);
FTimespan WindowStart = FTimespan(20, 0, 0); // 20:00
FTimespan WindowEnd   = FTimespan(22, 0, 0); // 22:00
bool bInWindow = (TimeNow >= WindowStart && TimeNow < WindowEnd);

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.