hms
Hour, minute and second of a datetime.
Category: Language Fundamentals > Data Types
Syntax
[h, m, s] = hms(t)
Returns the time-of-day components of t.
Description
hms returns the time-of-day parts of each datetime. Asking for fewer outputs returns the leading ones, so h = hms(t) gives only the hour. The date part is ignored.
Input arguments
tdatetimearray.
Output arguments
h, m, s- Numeric arrays the size of
t: hour (0 to 23), minute (0 to 59) and second (0 up to 60, with fraction).
Example
Splitting a time
t = datetime(2024, 3, 5, 14, 30, 15);
[h, m, s] = hms(t)
Output
h = 14
m = 30
s = 15