Convert Unix Time in Date Time Format with Milliseconds
Show older comments
Hello,
i want to convert Unix Time Stamp like this 1545390864126080000 (1.545^18) in a Format like this "Friday, 21. December 2018 11:14:24.126".
I use:
date_time = datestr(unix_time_pose./86400 + datenum(1970,1,1));
unix_time_pose vector is Unix_Time/10^9 and i get something like this '21-Dec-2018 12:04:58'. It is the right date without milliseconds.
Can anyone help me how to get milliseconds,too?
2 Comments
James Tursa
on 6 Feb 2019
Edited: James Tursa
on 6 Feb 2019
What does this show:
whos unix_time_pose
Sarah Maag
on 7 Feb 2019
Accepted Answer
More Answers (1)
eldar
on 11 Sep 2024
If you are reading data in unix timestamp from a .CSV file with a floating point as milliseconds what worked for me was,
dt = datetime(1970,1,1,'Format','dd-MMM-yyyy HH:mm:ss.SSS') + tableData.UnixTime/86400;
3 Comments
Peter Perkins
on 21 Nov 2024
Eldar, this works, but you will likely be happier using the much simpler
datetime(unixTime,"ConvertFrom","posixtime")
eldar
on 24 Nov 2024
Hi Peter, I tried that at first but for some reason did not get the precession that was needed.
Peter Perkins
on 25 Nov 2024
I don't know what that means, but surely if you are converting from seconds to days (using UnixTime/86400) you will be introducing unnecessary noise into your calculations, even if very small.
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!