Borrar filtros
Borrar filtros

from posix to date

116 visualizaciones (últimos 30 días)
Valeria Leto
Valeria Leto el 4 de Mzo. de 2020
Comentada: Valeria Leto el 7 de Mzo. de 2020
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 comentarios
Guillaume
Guillaume el 4 de Mzo. de 2020
"where is the problem?"
Your input is not a posix time, most likely. What is the value of t_ne?
Valeria Leto
Valeria Leto el 4 de Mzo. de 2020
it's 1582650648869329937

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 4 de Mzo. de 2020
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 comentarios
Walter Roberson
Walter Roberson el 5 de Mzo. de 2020
Yup, the complications are to preserve the 17 nanoseconds.
Valeria Leto
Valeria Leto el 7 de Mzo. de 2020
thanks a lot! very kind :)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by