from posix to date

167 次查看(过去 30 天)
Hi,
I am trying to use this command to convert the time vector t_ne expressed in posix time to a date
d = datetime(t_ne, 'ConvertFrom', 'posixtime')
but I get
datetime
5.0152e+10 CE
where is the problem?
  2 个评论
Guillaume
Guillaume 2020-3-4
"where is the problem?"
Your input is not a posix time, most likely. What is the value of t_ne?
Valeria Leto
Valeria Leto 2020-3-4
it's 1582650648869329937

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2020-3-4
This is a bit tricky because you are working past double precision accuracy.
t_ne = uint64(1582650648869329937);
NS = 1e9;
right_over = mod(t_ne, NS);
left_over = t_ne - right_over;
d = datetime( double(left_over)/NS, 'convertfrom', 'posixtime', 'Format', 'dd-MMM-uuuu HH:mm:ss.SSSSSSSSS') + seconds(double(right_over)/NS)
  4 个评论
Walter Roberson
Walter Roberson 2020-3-5
Yup, the complications are to preserve the 17 nanoseconds.
Valeria Leto
Valeria Leto 2020-3-7
thanks a lot! very kind :)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by