[英]Convert Binance timestamp into valid datetime
I dont know how to covert timestamp given by Binance server into valid DateTime
.我不知道如何将 Binance 服务器给出的时间戳转换为有效的
DateTime
。
Binance.API.Csharp.Client.Models.General.ServerInfo
returns 1615724572987
which after conversion to DateTime
gives 1/2/0001 9:52:52 PM
which obviously is not correct. Binance.API.Csharp.Client.Models.General.ServerInfo
返回1615724572987
转换为DateTime
后给出1/2/0001 9:52:52 PM
这显然是不正确的。
I tried to find description about ServerInfo type but there is only GetHtml Function.我试图找到有关 ServerInfo 类型的描述,但只有 GetHtml Function。
From this question you will learn that从这个问题中你会了解到
"[In binance API] All time and timestamp related fields are in milliseconds."
“[在 Binance API 中] 所有时间和时间戳相关的字段都以毫秒为单位。” (unix style)
(Unix风格)
And from this question you will learn to convert unix timestamp to DateTime
.从这个问题中,您将学习将 unix 时间戳转换为
DateTime
。
Then combine this knowledge to create this method:然后结合这些知识来创建这个方法:
public static DateTime BinanceTimeStampToUtcDateTime(double binanceTimeStamp)
{
// Binance timestamp is milliseconds past epoch
var epoch = new DateTime(1970,1,1,0,0,0,0,System.DateTimeKind.Utc);
return epoch.AddMilliseconds(binanceTimeStamp);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.