UKismetMathLibrary::GetHour12
#include "Kismet/KismetMathLibrary.h"
Access: public
Specifiers: staticUFUNCTIONBlueprintPure
Description
Returns the hour component of A in 12-hour clock format (1–12). Midnight returns 12, noon returns 12. Use this for AM/PM display in the UI.
Caveats & Gotchas
- • Both midnight (00:xx) and noon (12:xx) return 12. To distinguish AM from PM you must also check IsAfternoon() or compare GetHour() against 12.
- • The range is 1–12, not 0–11. Hour 12 represents both midnight and noon — code expecting 0 at midnight (as some 12-hour clock libraries use) will be incorrect.
Signature
static UE_INL_API int32 GetHour12( FDateTime A ); Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| A | FDateTime | The date-time to extract the 12-hour clock hour from. | — |
Return Type
int32 Example
Format a 12-hour clock string C++
FDateTime Now = FDateTime::UtcNow();
int32 Hour12 = UKismetMathLibrary::GetHour12(Now);
int32 Minute = UKismetMathLibrary::GetMinute(Now);
bool bPM = UKismetMathLibrary::IsAfternoon(Now);
FString TimeStr = FString::Printf(TEXT("%d:%02d %s"), Hour12, Minute, bPM ? TEXT("PM") : TEXT("AM")); Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?