keywords: [UE4]Time时间相关

获取系统时间以及UNIX时间戳

蓝图:

//返回值为从启动游戏开始的经过时长(单位秒),而非Unix时间戳
float UKismetSystemLibrary::GetGameTimeInSeconds(UObject* WorldContextObject);

C++代码:

FDateTime Time = FDateTime::Now();
int64 Timestamp = Time.ToUnixTimestamp();
将 Unix Timestamp 转换为年月日(year, month, day)
FDateTime Time = FDateTime::FromUnixTimestamp(int64 UnixTime);
获取系统当前日期时间:年月日时分秒
FDateTime Time = FDateTime::Now();

int Year = Time.GetYear();
int Month = Time.GetMonth();
int Day = Time.GetDay();

int Hour = Time.GetHour();
int Minute = Time.GetMinute();
int Second = Time.GetSecond();
获取CPU时钟周期
//微妙格式
uint64 cycle = FPlatformTime::Cycles64();
uint32 cycle = FPlatformTime::Cycles();
//秒格式
double now = FPlatformTime::Seconds();
How to get delta time (frame cost) of current frame
float DeltaTime = FApp::GetDeltaTime();
Return the time difference from the current system time
UWorld::TimeSince(double time)
Get last modified time of file

headers:

#include "Runtime/Core/Public/GenericPlatform/GenericPlatformFile.h"
#include "HAL/PlatformFilemanager.h"

API:

IPlatformFile& Handle = FPlatformFileManager::Get().GetPlatformFile();
FDateTime Time = Handle.GetTimeStamp(TEXT("path-to-file"));