Documentation

hms

Hour, minute, and second numbers of duration

Syntax

[h,m,s] = hms(t)

Description

example

[h,m,s] = hms(t)returns the hour, minute, and second values of the datetime values intas separate numeric arrays. Thehandmoutputs contain integer values, and thesoutput can contain a fractional part.h,m, andsare the same size ast.

Callinghmsis equivalent to calling thehour,minute, andsecondfunctions.

Examples

collapse all

t1 = datetime('now','Format','HH:mm:ss.SSS'); t = t1 + minutes(0:45:135)
t =1x4 datetime array17:03:31.419 17:48:31.419 18:33:31.419 19:18:31.419
[h,m,s] = hms(t)
h =1×417 17 18 19
m =1×43 48 33 18
s =1×431.4192 31.4192 31.4192 31.4192

hmsreturns the hour, minute, and second numbers in separate arrays.

Input Arguments

collapse all

Input date and time, specified as adatetimearray.

Output Arguments

collapse all

Hour numbers, returned as a numeric array of integer values from 0 to 23. Thehoutput is of typedoubleand is the same size ast.

Minute numbers, returned as a numeric array of integer values from 0 to 59. Themoutput is of typedoubleand is the same size ast.

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 isUTCLeapSeconds,soutput can contain a value between 60 and 61 for times that fall during a leap second occurrence. Thesoutput is of typedoubleand is the same size ast.

Extended Capabilities

See Also

|||

Introduced in R2014b

Was this topic helpful?