简体   繁体   中英

Convert Binance timestamp into valid datetime

I dont know how to covert timestamp given by Binance server into valid 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.

I tried to find description about ServerInfo type but there is only GetHtml Function.

From this question you will learn that

"[In binance API] All time and timestamp related fields are in milliseconds." (unix style)

And from this question you will learn to convert unix timestamp to 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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM