How to convert unix to DateTime?

Is there a way to convert unix time to date time in blueprints?

Example: 1624382981 → 2021-06-22 17:36:52

Thanks a lot.
Sometimes the answer can be way easier than you expect :smiley:

Hey,
you could add the unix seconds to a MakeDateTime

3 Likes

I think the add node not working in ue5.1 anymore. Do you have another way to do this?

You could try this:

Or use C++, or use a python script or…

1 Like

Good news the simple solution pointed out by L1z4rD89 is still working in UE5.1 ! The “add” node is buggy but by edditing the connexion inside the text editor it is possible ti make the connexion. And then you can just copy past :

Code to copy

Begin Object Class=/Script/BlueprintGraph.K2Node_CallFunction Name=“K2Node_CallFunction_23”
bIsPureFunc=True
FunctionReference=(MemberParent=/Script/CoreUObject.Class’“/Script/Engine.KismetMathLibrary”‘,MemberName=“MakeTimespan”)
NodePosX=2272
NodePosY=1888
NodeGuid=62F075194CBC6F4D4DD623A55C4837D9
CustomProperties Pin (PinId=8E09A0FA4D1F0413D5B77DA1D6E9507C,PinName=“self”,PinFriendlyName=NSLOCTEXT(“K2Node”, “Target”, “Target”),PinToolTip=“Target\nKismet Math Library Object Reference”,PinType.PinCategory=“object”,PinType.PinSubCategory=“”,PinType.PinSubCategoryObject=/Script/CoreUObject.Class’“/Script/Engine.KismetMathLibrary”‘,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,DefaultObject=“/Script/Engine.Default__KismetMathLibrary”,PersistentGuid=00000000000000000000000000000000,bHidden=True,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
CustomProperties Pin (PinId=AAAF80A6464ABFC5CF5C0EA941A71185,PinName=“Days”,PinToolTip=“Days\nInteger”,PinType.PinCategory=“int”,PinType.PinSubCategory=“”,PinType.PinSubCategoryObject=None,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,DefaultValue=“0”,AutogeneratedDefaultValue=“0”,PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
CustomProperties Pin (PinId=29BBD4404AE1BEF0588AC3892B75F416,PinName=“Hours”,PinToolTip=“Hours\nInteger”,PinType.PinCategory=“int”,PinType.PinSubCategory=“”,PinType.PinSubCategoryObject=None,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,DefaultValue=“0”,AutogeneratedDefaultValue=“0”,PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
CustomProperties Pin (PinId=4DEC0F444C4E990E84B5E097CE557023,PinName=“Minutes”,PinToolTip=“Minutes\nInteger”,PinType.PinCategory=“int”,PinType.PinSubCategory=“”,PinType.PinSubCategoryObject=None,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,DefaultValue=“0”,AutogeneratedDefaultValue=“0”,PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
CustomProperties Pin (PinId=580110A34AAFB7EC853E5EB06EBEEF5B,PinName=“Seconds”,PinToolTip=“Seconds\nInteger”,PinType.PinCategory=“int”,PinType.PinSubCategory=“”,PinType.PinSubCategoryObject=None,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,DefaultValue=“0”,AutogeneratedDefaultValue=“0”,LinkedTo=(K2Node_GetJsonField_10 792171FE4913FC2B78A3498A1821D80E,),PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
CustomProperties Pin (PinId=77B24616417E2141CA19F7AB9E4BF6A8,PinName=“Milliseconds”,PinToolTip=“Milliseconds\nInteger”,PinType.PinCategory=“int”,PinType.PinSubCategory=“”,PinType.PinSubCategoryObject=None,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,DefaultValue=“0”,AutogeneratedDefaultValue=“0”,PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
CustomProperties Pin (PinId=389551A4430DD1C1FF4670A89B3BD0A6,PinName=“ReturnValue”,PinToolTip=“Return Value\nTimespan Structure\n\nMakes a Timespan struct”,Direction=“EGPD_Output”,PinType.PinCategory=“struct”,PinType.PinSubCategory=“”,PinType.PinSubCategoryObject=/Script/CoreUObject.ScriptStruct’“/Script/CoreUObject.Timespan”‘,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,LinkedTo=(K2Node_PromotableOperator_2 B127146E4C19B1C5340C5B95410BD60E,),PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
End Object
Begin Object Class=/Script/BlueprintGraph.K2Node_CallFunction Name=“K2Node_CallFunction_24”
bIsPureFunc=True
FunctionReference=(MemberParent=/Script/CoreUObject.Class’“/Script/Engine.KismetMathLibrary”‘,MemberName=“MakeDateTime”)
NodePosX=2288
NodePosY=1728
AdvancedPinDisplay=Hidden
NodeGuid=75A65CD641F74310E285B98A54F9B2DD
CustomProperties Pin (PinId=A81667F74CC5BA1B01F75EB4B3CE0D99,PinName=“self”,PinFriendlyName=NSLOCTEXT(“K2Node”, “Target”, “Target”),PinToolTip=“Target\nKismet Math Library Object Reference”,PinType.PinCategory=“object”,PinType.PinSubCategory=“”,PinType.PinSubCategoryObject=/Script/CoreUObject.Class’“/Script/Engine.KismetMathLibrary”‘,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,DefaultObject=“/Script/Engine.Default__KismetMathLibrary”,PersistentGuid=00000000000000000000000000000000,bHidden=True,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
CustomProperties Pin (PinId=9C8C5C13435EE1F153C4129D87389045,PinName=“Year”,PinToolTip=“Year\nInteger”,PinType.PinCategory=“int”,PinType.PinSubCategory=“”,PinType.PinSubCategoryObject=None,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,DefaultValue=“1970”,AutogeneratedDefaultValue=“0”,PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
CustomProperties Pin (PinId=E769385F48629760005BDDB3E8EFA43D,PinName=“Month”,PinToolTip=“Month\nInteger”,PinType.PinCategory=“int”,PinType.PinSubCategory=“”,PinType.PinSubCategoryObject=None,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,DefaultValue=“1”,AutogeneratedDefaultValue=“0”,PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
CustomProperties Pin (PinId=22EF373E45081360A21B08B858F64A1C,PinName=“Day”,PinToolTip=“Day\nInteger”,PinType.PinCategory=“int”,PinType.PinSubCategory=“”,PinType.PinSubCategoryObject=None,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,DefaultValue=“1”,AutogeneratedDefaultValue=“0”,PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
CustomProperties Pin (PinId=1C32B98F4D996A53D39BD39A1B09DBF5,PinName=“Hour”,PinToolTip=“Hour\nInteger”,PinType.PinCategory=“int”,PinType.PinSubCategory=“”,PinType.PinSubCategoryObject=None,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,DefaultValue=“0”,AutogeneratedDefaultValue=“0”,PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=True,bOrphanedPin=False,)
CustomProperties Pin (PinId=C88CE3E040C974C0AFDC038626354668,PinName=“Minute”,PinToolTip=“Minute\nInteger”,PinType.PinCategory=“int”,PinType.PinSubCategory=“”,PinType.PinSubCategoryObject=None,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,DefaultValue=“0”,AutogeneratedDefaultValue=“0”,PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=True,bOrphanedPin=False,)
CustomProperties Pin (PinId=A0B6AEE5434D8F83A3DEFBBF1932FF75,PinName=“Second”,PinToolTip=“Second\nInteger”,PinType.PinCategory=“int”,PinType.PinSubCategory=“”,PinType.PinSubCategoryObject=None,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,DefaultValue=“0”,AutogeneratedDefaultValue=“0”,PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=True,bOrphanedPin=False,)
CustomProperties Pin (PinId=97DF6A6D477CF9DBF4D25AB17F78C160,PinName=“Millisecond”,PinToolTip=“Millisecond\nInteger”,PinType.PinCategory=“int”,PinType.PinSubCategory=“”,PinType.PinSubCategoryObject=None,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,DefaultValue=“0”,AutogeneratedDefaultValue=“0”,PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=True,bOrphanedPin=False,)
CustomProperties Pin (PinId=AA084CF04C9F3C12FBAE7B8A161E3337,PinName=“ReturnValue”,PinToolTip=“Return Value\nDate Time Structure\n\nMakes a DateTime struct”,Direction=“EGPD_Output”,PinType.PinCategory=“struct”,PinType.PinSubCategory=“”,PinType.PinSubCategoryObject=/Script/CoreUObject.ScriptStruct’“/Script/CoreUObject.DateTime”‘,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,LinkedTo=(K2Node_PromotableOperator_2 ED2A6A1F476B391FCEA11BBCC450B12C,),PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
End Object
Begin Object Class=/Script/BlueprintGraph.K2Node_PromotableOperator Name=“K2Node_PromotableOperator_2”
bIsPureFunc=True
FunctionReference=(MemberParent=/Script/CoreUObject.Class’“/Script/Engine.KismetMathLibrary”‘,MemberName=“Add_DateTimeTimespan”)
NodePosX=2624
NodePosY=1808
NodeGuid=D06586174E2005F467F3FC8F5FDEF486
CustomProperties Pin (PinId=ED2A6A1F476B391FCEA11BBCC450B12C,PinName=“A”,PinToolTip=“A\nDate Time Structure”,PinType.PinCategory=“struct”,PinType.PinSubCategory=“”,PinType.PinSubCategoryObject=/Script/CoreUObject.ScriptStruct’“/Script/CoreUObject.DateTime”‘,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,LinkedTo=(K2Node_CallFunction_24 AA084CF04C9F3C12FBAE7B8A161E3337,),PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
CustomProperties Pin (PinId=B127146E4C19B1C5340C5B95410BD60E,PinName=“B”,PinToolTip=“B\nTimespan Structure”,PinType.PinCategory=“struct”,PinType.PinSubCategory=“”,PinType.PinSubCategoryObject=/Script/CoreUObject.ScriptStruct’“/Script/CoreUObject.Timespan”‘,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,LinkedTo=(K2Node_CallFunction_23 389551A4430DD1C1FF4670A89B3BD0A6,),PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
CustomProperties Pin (PinId=DBE927F34BE7E259648A679D01500839,PinName=“ReturnValue”,PinToolTip=“Return Value\nDate Time Structure\n\nAddition (A + B)”,Direction=“EGPD_Output”,PinType.PinCategory=“struct”,PinType.PinSubCategory=“”,PinType.PinSubCategoryObject=/Script/CoreUObject.ScriptStruct’“/Script/CoreUObject.DateTime”‘,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,LinkedTo=(K2Node_Knot_0 4494187D4D5CDDEE7BDE93ABB562D5DE,),PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
End Object
Begin Object Class=/Script/BlueprintGraph.K2Node_Knot Name=“K2Node_Knot_0”
NodePosX=2784
NodePosY=1808
NodeGuid=254951114307874D731242A489DACE1D
CustomProperties Pin (PinId=4494187D4D5CDDEE7BDE93ABB562D5DE,PinName=“InputPin”,PinType.PinCategory=“struct”,PinType.PinSubCategory=“”,PinType.PinSubCategoryObject=/Script/CoreUObject.ScriptStruct’“/Script/CoreUObject.DateTime”‘,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,LinkedTo=(K2Node_PromotableOperator_2 DBE927F34BE7E259648A679D01500839,),PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=True,bAdvancedView=False,bOrphanedPin=False,)
CustomProperties Pin (PinId=71564CE540559CC6EE743ABFDE2F42AB,PinName=“OutputPin”,Direction=“EGPD_Output”,PinType.PinCategory=“struct”,PinType.PinSubCategory=“”,PinType.PinSubCategoryObject=/Script/CoreUObject.ScriptStruct’“/Script/CoreUObject.DateTime”',PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,LinkedTo=(K2Node_CallFunction_47 908FD6B145458DAC46078CB0F91DF057,K2Node_CallFunction_49 D3F3D3424358F28B525BA18F636C695A,),PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
End Object

Amazing! can I know the value you’ve put for Str Start date please?

Hey @Maddy13294

the string contains:

1970-01-01T00:00:00-

Here is a snippet

1 Like

I know it was requested to be in BP, but sometimes creating big workarounds just not to use C++ is even more difficult.

This could be done pretty easily just by creating C++ class inherited from BlueprintFunctionLibrary.
Add this to .h:

	UFUNCTION(BlueprintCallable, BlueprintPure)
	static FDateTime UnixToDateTime(int64 UnixTime);

This to cpp:

FDateTime YourLibraryClassName::UnixToDateTime(int64 UnixTime)
{
	FDateTime DataTime;
	DataTime.FromUnixTimestamp(UnixTime);
	return DataTime;
}

Replace “YourLibraryClassName” with name of your class.

And pretty much it, you have such node available:

1 Like

thanks for your code!
I test this code but always got 0001.01.01-00.00.00

FDateTime UTestBlueprintFunctionLibrary::UnixToDateTime(int64 UnixTime)
{
	return FDateTime(1970, 1, 1) + FTimespan(0,0,UnixTime);
}

I try to fix this error.
this is my code.

1 Like

You are right, so sorry about this. Not sure why UE function is not working correctly, but this works fine for me:

FDateTime UTestBlueprintFunctionLibrary::UnixToDateTime(int64 UnixTime)
{
	return FDateTime(UnixTime * ETimespan::TicksPerSecond) + FDateTime(1970, 1, 1);
}

Note: this function is meant to use for short format Epoch (Unix) time. For those Timestamp formats that include nano seconds (for example: 17138563369669126) replace that line with this:

return FDateTime(UnixTime) + FDateTime(1970, 1, 1);

1 Like