Converting Epoch time to HH:MM

9 Ansichten (letzte 30 Tage)
Ronaldo95163
Ronaldo95163 am 8 Apr. 2016
Beantwortet: E Zakreski am 8 Apr. 2016
If I have a vector of time values in epoch time...can I convert it into the format HH:MM using matlab and plot a graph with it...so Y vs Time(time in HH:MM)??
If not can I make a vector already containing the converted time values and plot the same graph??
Thanks
  2 Kommentare
Star Strider
Star Strider am 8 Apr. 2016
I was obviously away when ‘epoch time’ was described. Please define it for me.
How does it relate to MATLAB time?
Ronaldo95163
Ronaldo95163 am 8 Apr. 2016
Its the time elapsed in s since 1/1/1970...so an example would be like 1383260400

Melden Sie sich an, um zu kommentieren.

Antworten (1)

E Zakreski
E Zakreski am 8 Apr. 2016
First plot your data in unix time
function [axh,ploth] = makePlot(ydata,unixtime)
axh=axes('nextplot','add');
%add listener to update axes x-tick labels
addlistener(axh,'XLim','PostSet',@(src,ev)set(ev.AffectedObject,'xticklabel',... unixtime2datestr(ev.AffectedObject.XTick));
%make plot
plot(unixtime,ydata,'parent',axh);
end
function dastr = unixtime2datestr(unixtime) %Make X-tick labels read as HH:MM. %Unix time in seconds.
%roll back by 4 hours to get eastern time (otherwise leave in GMT)
unixtime = unixtime - 4*3600;
unix_epoch = datenum(1970,1,1,0,0,0); matlab_time = unixtime./86400 + unix_epoch;
dformat='HH:MM';
dastr = datestr(matlab_time,dformat);
end
Hope this helps :)

Kategorien

Mehr zu Dates and Time finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by