Conversion from unix time string to uint64
Mostrar comentarios más antiguos
I have lidar sensor data and every file is named on its timestamps. The file name 25 characters long (21 characters for time stamps and 4 characters for extension).
For example first file name is "1520944184833390730.pcd"
When I try to convert it to uint64
timeNum = uint64(str2num(fileNames(1:end-4)));
It gives
timeNum = 1520944184833390848
2 comentarios
Correctly. What is your question? You cannot store 25 digits exactly in an uint64. 2^64 is about 10^19.26, so you can expect 19 valid digits only. But as long as you do not mention, what your question is, it is not clear, how to help you.
Maybe the first 16 digits are the seconds, and the last 9 the nanoseconds?
Geoff Hayes
el 20 de Feb. de 2019
Editada: Geoff Hayes
el 20 de Feb. de 2019
Hafiz - what does
str2num(fileNames(1:end-4))
return? Perhaps you are losing some precision with str2num... What happens if you use str2double instead?
In your above example, there are 19 digits in the name (less the extension) but you say The file name 25 characters long (21 characters for time stamps and 4 characters for extension). Which is correct?
Respuesta aceptada
Más respuestas (2)
Peter Perkins
el 21 de Feb. de 2019
I'm gonna run with Jan's guess, which, in the absence of any description, seems plausible:
>> datetime(1520944184833390730/1e9,'convertFrom','posixtime')
ans =
datetime
13-Mar-2018 12:29:44
Lets say you have that character string.
>> t = '1520944184833390730.pcd';
>> secs = str2num(t(1:10))
secs =
1520944184
>> ns = str2num(t(11:19))
ns =
833390730
>> d = datetime(secs,'ConvertFrom','posixtime','Format','dd-MMM-yyyy HH:mm:ss.SSSSSSSSS') + milliseconds(ns/1e6)
d =
datetime
13-Mar-2018 12:29:44.833390730
Hafiz Luqman
el 25 de Feb. de 2019
Editada: Hafiz Luqman
el 25 de Feb. de 2019
1 comentario
Jan
el 25 de Feb. de 2019
I'm not sure, what you mean. The current syntax is not valid and uint64('12345') does not create the variable 12345 as UINT64.
Categorías
Más información sobre Data Type Conversion en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!