How do I apply the convert epoch time formula to an array?
Show older comments
Hi, I have an array of 522 epoch time stamps that I want to convert to human readable form. I am not sure how to convert it and plot it. Your help would be greatly appreciated. Thanks!
time_unix = 1480518828; % example time
time_reference = datenum('2017', 'yyyy');
time_matlab = time_reference + time_unix / 8.64e7;
time_matlab_string = datestr(time_matlab, 'yyyymmdd HH:MM:SS.FFF')
figure('Color', 'White')
reftime=dataset1 (:,1); %Follower Actual (Excel column G2)
ylabel('TBD1')
xlabel('TBD2')
legend('Epock Time''Location', 'northwest')
title('Ephoch Time Conversion')
grid
Answers (1)
Walter Roberson
on 26 Jan 2017
0 votes
That is not the correct conversion for Unix or Posix time. The time base is January 1st 1970 utc. The number field is either seconds since then (traditional) or milliseconds since then (commonly seen), except that Posix time does not account for leap seconds so you have to be careful on the conversion.
I recommend that if you have a sufficiently new MATLAB that you use datetime() with 'convertfrom', 'posixtime'
3 Comments
Lidia Toscano
on 26 Jan 2017
Walter Roberson
on 26 Jan 2017
You can pass the array as the first parameter to datetime
Kerman Sekhon
on 6 Jan 2019
Hello,
Thank you for your guidance. I was wondering what you meant by pass the array as the first parameter to datetime? Thank you for your time!
Kind Regards
Categories
Find more on MATLAB in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!