time to number conversion

10 次查看(过去 30 天)
I have a cell array that has the following format: v0={'1/4/2011','12:17:09'} I converted the date to number using the datenum(v0(1,1),'mm/dd/yyyy'); but the question is how to convert the time '12:17:09' to a number? is it possible to merge v0(1,1) with v0(1,2) to obtain the date using timen=datenum(time,'dd/mm/yyyy HH:MM:SS')? so basically I am ok with conversing time alone to number or date & time (merged) to number. Any help is greatly appreciated

采纳的回答

Geoff
Geoff 2012-7-22
From memory, if you use datenum to just get the time with no date, it doesn't return a number between 0 and 1. But you can get around that with mod.... So here's one option:
d = datenum(v0{1}, 'mm/dd/yyyy') + mod(datenum(v0{2}, 'HH:MM:SS'), 1);
The other way is to construct a string with both combined:
str = [v0{1}, ' ', v0{2}];
d = datenum(str, 'mm/dd/yyyy HH:MM:SS');

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by