How do I apply the convert epoch time formula to an array?

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)

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

Great answer, that gives me the right date and time for one time stamp. datetime(1480518828, 'convertfrom','posixtime')
Now how do I get the conversion for an array of 522 time stamps?
Thanks in advance!
You can pass the array as the first parameter to datetime
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

Sign in to comment.

Categories

Find more on MATLAB in Help Center and File Exchange

Products

Asked:

on 26 Jan 2017

Commented:

on 6 Jan 2019

Community Treasure Hunt

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

Start Hunting!