# How to calculate time elapsed for AM and PM

조회 수: 11 (최근 30일)
Mekala balaji 2018년 3월 19일
댓글: Mekala balaji 2018년 3월 19일
Hi,
I have below time array:
Start time End time
23:12:17 PM 23:12:19 PM
3:12:11 AM 3:12:29 AM
23:59:17 PM 01:10:13 AM
11:59:17 AM 13:10:13 PM
I want to calculate time elapsed between Start time to End time of each row.

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

### 답변 (2개)

Image Analyst 2018년 3월 19일
See the help for etime().
##### 댓글 수: 3이전 댓글 1개 표시이전 댓글 1개 숨기기
Image Analyst 2018년 3월 19일
If the time is negative, add 24 hours to it.
Mekala balaji 2018년 3월 19일
Sir,
I tried as below, but it seems some problem,
t1={'23:59:00 PM'}
t1 =
cell
'23:59:00 PM'
>> t2={'00:1:00 AM'}
t2 =
cell
'00:1:00 AM'
>> t2={'12:1:00 AM'}
t2 =
cell
'12:1:00 AM'
>> t1=datevec(t1)
t1 =
2018 1 2 11 59 0
>> t2=datevec(t2)
t2 =
2018 1 1 0 1 0
>> etime(t2,t1)
ans =
-129480

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

Star Strider 2018년 3월 19일
You should add dates to each time, and delete the ‘AM’ and ‘PM’ since you are also using 24-hour times.
Try this:
SA = {'23:12:17' '23:12:19'
'3:12:11' '3:12:29'
'23:59:17' '01:10:13'
'11:59:17' '13:10:13'};
DA = datetime(SA, 'InputFormat','HH:mm:ss');
BT = between(DA(:,1), DA(:,2));
It will give a negative value for Row 3, because the between function does not ‘know’ they are consecutive days, since you did not tell it.

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

### 카테고리

Help CenterFile Exchange에서 National Instruments Frame Grabbers에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by