How to calculate time elapsed

3 vues (au cours des 30 derniers jours)
Mekala balaji
Mekala balaji le 16 Fév 2016
Modifié(e) : Stephen23 le 18 Fév 2016
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

Réponse acceptée

Stephen23
Stephen23 le 16 Fév 2016
>> 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 commentaires
Mekala balaji
Mekala balaji le 18 Fév 2016
Hi Sir,
It works, but one thing I have several continuous data, want to calculate time elapsed between two consecutive data points. But the problem is any two consecutive data may happen at two different time(one is in 'AM', and other one is 'PM'). So, how to handle it. Sincerely, Mekala
Stephen23
Stephen23 le 18 Fév 2016
Modifié(e) : Stephen23 le 18 Fév 2016
@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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by