clock

Current date and time as a six-element vector.

Category: Language Fundamentals > Data Types

Syntax

c = clock

Returns [year month day hour minute seconds].

Description

The first five elements are whole numbers in the local time zone and the sixth holds the seconds with fractions. The vector can be passed to datenum or etime. The newer datetime('now') is recommended in new code.

Because the value depends on when it runs, the result is not reproducible; take only the parts you need, such as the year.

Output arguments

c
1-by-6 double vector. The seconds element has a fractional part.

Example

Shape of the result

c = clock;
size(c)
c(1) >= 2024
Output
ans = 1×2

     1     6
ans = logical
   1

See also

datetime datenum datevec tic date