RealDocs

UKismetMathLibrary::TimespanFromString

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

Description

Parses an FTimespan from its canonical string representation. Returns true on success, false if the string is malformed. Use this when deserialising timespans from config files, save data, or network messages.

Caveats & Gotchas

  • The expected format is the output of FTimespan::ToString(): "-d.hh:mm:ss.fff" where the day and millisecond parts are optional. Formats like "1h30m" or ISO 8601 durations are not accepted and will return false.
  • Result is not zeroed on parse failure — it retains whatever value it held before the call. Always check the return value before using Result.

Signature

static UE_INL_API bool TimespanFromString(FString TimespanString, FTimespan& Result);

Parameters

Name Type Description Default
TimespanString FString String in the format "-d.hh:mm:ss.fff" or a subset thereof.
Result FTimespan& Populated with the parsed timespan on success; unchanged on failure.

Return Type

bool

Example

Parse a timespan from a config string C++
FString RawValue = GameConfig->GetValue(TEXT("CooldownDuration"));
FTimespan Cooldown;
if (!UKismetMathLibrary::TimespanFromString(RawValue, Cooldown))
{
    UE_LOG(LogGame, Warning, TEXT("Invalid cooldown string: %s"), *RawValue);
    Cooldown = UKismetMathLibrary::FromSeconds(30.0); // fallback
}

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.