필터 지우기
필터 지우기

Converting hh:mm:ss into seconds

조회 수: 271 (최근 30일)
tethys
tethys 2012년 1월 20일
답변: Steven Lord 2021년 9월 1일
Hi all,
I want to read the vectors which are hh:mm:ss (14:35:59.812) format and convert it to seconds. How can I do this in matlab?
Best

채택된 답변

Andreas Goser
Andreas Goser 2012년 1월 20일
Is this what you are looking for?
t='14:35:59.812';
[Y, M, D, H, MN, S] = datevec(t);
H*3600+MN*60+S
  댓글 수: 4
per isakson
per isakson 2016년 12월 3일
On R2016a I get the expected result
>> dt = datestr( now,'HH:MM:SS,FFF')
dt =
12:58:26,797
Arshey Dhangekar
Arshey Dhangekar 2021년 9월 1일
I want to convert Time column ( HH:MM:SS) to min, there is a direct command time2num but it requires toolbox and it's paid.So without using time2num how can I convert into minutes. I tried with datetime also but I got error.
table=readtable('sample.csv'):
times = datetime(table.Time,'InputFormat','HH:mm:ss:SSS');
times = hour(times).*60 + minute(times) + second(times)./60;

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

per isakson
per isakson 2012년 1월 20일
The first and the last cell returns the result I think you are looking for. See help on DATENUM
datenum( '14:35:59.812', 'HH:MM:SS.FFF' ) .* (24*60*60) - ...
datenum( '00:00:00.000', 'HH:MM:SS.FFF' ) .* (24*60*60)
datestr( datenum( '00:00:00.000', 'HH:MM:SS.FFF' ), 'yyyy-mm-dd' )
datenum( '14:35:59.812', 'HH:MM:SS.FFF', 0 ) .* (24*60*60)
  댓글 수: 1
tethys
tethys 2012년 1월 20일
Thansk for the answer, it is very useful information:)

댓글을 달려면 로그인하십시오.


Peter Seibold
Peter Seibold 2021년 4월 18일
About 100 times faster is:
t='14:35:59.812';
seconds=sum(sscanf(t,'%f:%f:%f').*[3600;60;1]);

Steven Lord
Steven Lord 2021년 9월 1일
t='14:35:59.812';
F = 'hh:mm:ss.SSS';
du = duration(t, 'InputFormat', F, 'Format', F)
du = duration
14:35:59.812
format longg % To make s look nicer
s = seconds(du)
s =
52559.812

카테고리

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