How to calculate time elapsed
1 次查看(过去 30 天)
显示 更早的评论
Hi, I have two time intervals in the following format:
t1=2/4/2016 1:53:19.180 AM t2=2/4/2016 1:54:49.368 AM
I want to calculate time elapsed between t1 &t2 in seconds. I used 'etime' command, but not succeed. Kindly some one help how to calculate.
Sincerely, Mekala
0 个评论
采纳的回答
Stephen23
2016-2-16
>> s1 = '2/4/2016 1:53:19.180 AM';
>> s2 = '2/4/2016 1:54:49.368 AM';
>> t1 = datevec(s1,'dd/mm/yyyy HH:MM:SS.FFF AM');
>> t2 = datevec(s2,'dd/mm/yyyy HH:MM:SS.FFF AM');
>> etime(t2,t1)
ans =
90.1880
2 个评论
Stephen23
2016-2-18
编辑:Stephen23
2016-2-18
@Mekala balaji: just try my code exactly as it is. The symbolic identifiers AM and PM are not treated as literals, but are used to check for an AM/PM designator, exactly as you want. This is explained in the datevec documentation.
I also tested my code before I submitted it, including on times with AM and PM, and it worked just fine.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!