Main Content

hms

Hour, minute, and second numbers of datetime or duration

Description

[h,m,s] = hms(t) returns the hour, minute, and second values of the datetime or duration values in t as separate numeric arrays. The h and m outputs contain integer values, and the s output can contain a fractional part. h, m, and s are the same size as t.

Calling hms on a datetime array is equivalent to calling the hour, minute, and second functions.

example

Examples

collapse all

t1 = datetime('now','Format','HH:mm:ss.SSS');
t = t1 + minutes(0:45:135)
t = 1×4 datetime
   19:53:04.860   20:38:04.860   21:23:04.860   22:08:04.860

[h,m,s] = hms(t)
h = 1×4

    19    20    21    22

m = 1×4

    53    38    23     8

s = 1×4

    4.8603    4.8603    4.8603    4.8603

hms returns the hour, minute, and second numbers in separate arrays.

Input Arguments

collapse all

Input dates and times, specified as a datetime or duration array.

Data Types: datetime | duration

Output Arguments

collapse all

Hour numbers, returned as a numeric array of integer values from 0 to 23. The h output is of type double and is the same size as t.

Minute numbers, returned as a numeric array of integer values from 0 to 59. The m output is of type double and is the same size as t.

Second numbers, returned as a numeric array of values from 0 to less than 60, and can include a fractional part. For datetime values whose time zone is UTCLeapSeconds, the s output can contain a value between 60 and 61 for times that fall during a leap second occurrence. The s output is of type double and is the same size as t.

Extended Capabilities

expand all

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced in R2014b

See Also

| | |