how to convert date to milliseconds (Binance format)
15 次查看(过去 30 天)
显示 更早的评论
I got this function some time ago to convert datetime from Binance format into Matlab format, but now I need to do viceversa too, so to convert a certain datetime into Binance milliseconds format.
function [out_date] = date_from_binance_to_dt(raw_date)
out_date = string(datestr(datevec(raw_date/60/60/24/1000) + [1970 0 0 0 0 0]));
end
Can someone please help me to create the inverse function of mine one?
Thank you!
3 个评论
采纳的回答
Steven Lord
2021-12-1
So your input is a number of milliseconds since January 1st, 1970?
msSince1970 = 1234567;
start = datetime(1970, 01, 01);
T1 = datetime(msSince1970,'ConvertFrom', ...
'epochtime', 'Epoch', start, 'TicksPerSecond', 1000)
% or
T2 = start + seconds(msSince1970/1000)
check = T1==T2
To go backwards, creating msSince1970 from T1:
ms = 1000*seconds(T1-start)
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!