Converting hh:mm:ss into seconds
古いコメントを表示
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
採用された回答
その他の回答 (3 件)
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)
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]);
t='14:35:59.812';
F = 'hh:mm:ss.SSS';
du = duration(t, 'InputFormat', F, 'Format', F)
format longg % To make s look nicer
s = seconds(du)
カテゴリ
ヘルプ センター および File Exchange で Dates and Time についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!