栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

UE4 unix13位时间戳 转Windows DateTime

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

UE4 unix13位时间戳 转Windows DateTime

步骤1:   首先创建一个父类为BlueprintFunctionLibrary的C++类

 2.命名为 BPF_UnixTimestampToDateTime ,会自动打开VS2019,生成一个类;

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "Misc/DateTime.h"
#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "BPF_UnixTimestampToDateTime.generated.h"


UCLASS()
class MYPROJECT_API UBPF_UnixTimestampToDateTime : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()
	//
	UFUNCTION(BlueprintPure, Category = "UnixTimestamp")
		static FDateTime UnixTimestampToDateTime(int64 UnixTime);
	UFUNCTION(BlueprintPure, Category = "UnixTimestamp")
		static FDateTime UnixTimestampToDateTime_s(FString UnixTime);
};

上面这段代码,值得注意的是,每个想要暴露给蓝图的函数或者变量,都必须要声明

比如: UFUNCTION(BlueprintPure, Category = "UnixTimestamp")

// Fill out your copyright notice in the Description page of Project Settings.


#include "BPF_UnixTimestampToDateTime.h"


FDateTime UBPF_UnixTimestampToDateTime::UnixTimestampToDateTime_s(FString UnixTime)
{
	char* result = TCHAR_TO_ANSI(*UnixTime);
	uint64 unixTime_t = _atoi64(result);
	uint64 tmpUnix = unixTime_t / 1000;

	//sprintf(result, "%lld", unixTime_t);
	FDateTime Time = FDateTime::FromUnixTimestamp(tmpUnix);
	FTimespan spanT = FTimespan(8,0,0);
	Time = Time.operator+(spanT);		//UTC time +8 hour(china)/
	

	return Time;
}

因为linux系统传过来的时间戳是13位,然而UE4.26系统能转换的只有10位,所以需要除以1000(去掉毫秒部分),然后FromUnixTimestamp函数 才能得到正确的时间。

3.然后编译...  在蓝图里用;右键输入函数  UnixTimestampToDateTime_s

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1026172.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号