UNIX to seconds from beginning of the day

2 views (last 30 days)
I'm trying to convert UNIX (seconds from January 1, 1970) time to seconds from the beginning of the day.
I'm currently using this code, but I'd like seconds from the beginning of the day; I don't want a date string.
time_reference = datenum('1970', 'yyyy'); matrix(:,col.eTime) = time_reference + matrix(:,col.eTime) / 8.64e7; datestr(matrix(1,col.eTime), 'yyyymmdd HH:MM:SS.FFF')
Thanks, Lauren

Accepted Answer

James Tursa
James Tursa on 27 May 2014
One way:
ds = your_datestring_stuff;
dn = datenum(ds); % Turned into datenum format
s = (dn - floor(dn)) * 86400; % Seconds from beginning of the day
s = round(s*1000)/1000; % Get closest number to the .FFF fraction you want

More Answers (0)

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!