How do I convert tall array duration time vector to HH:mm:ss for merging with tall array datetime vector ?
조회 수: 11 (최근 30일)
이전 댓글 표시
Need some help with this. I have a tall array date vector 'yyyy-MM-dd' of datetime format, and a tall array time vector 'HH:mm:ss.SSS' of duration format. How do I convert the duration vector to only HH:mm:ss (omitting the decimals) and then combine that with the date vector to get: 'yyyy-MM-dd HH:mm:ss' ?
댓글 수: 0
채택된 답변
Chris
2022년 1월 21일
dates = tall(repmat(datetime(date),3,1))
times = tall(repmat(duration(15,12,1,345,'Format','hh:mm:ss.SSS'),3,1))
times.Format = 'hh:mm:ss';
datetime([string(dates) + " " + string(times)])
추가 답변 (1개)
Walter Roberson
2022년 1월 21일
perhaps
[h,m,s] = hms(DURATION_COLUMN);
DATETIME_COLUMN = TIME_COLUMN + duration(h,m,floor(s))
or perhaps
DATETIME_COLUMN = dateshift(TIME_COLUMN + DURATION_COLUMN, 'start', 'second')
if you do not have negative durations or negative datetimes, then adding first and then getting rid of the fractions of a second should give the same result.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!