clock
Current date and time as date vector
Syntax
Description
c = clock
returns a six-element date vector containing the current date
and time in decimal form:
[year month day hour minute seconds]
The clock
function calculates the current date and time from
the system time.
[c tf] = clock
returns a second output argument that is
1
(true
) if the current date and time
occur during Daylight Saving Time (DST) in your system's time zone, and
0
(false
) otherwise.
Examples
Limitations
MATLAB® Online™ returns current Coordinated Universal Time (UTC) rather than local time.
Tips
To time the duration of an event, use the
timeit
ortic
andtoc
functions instead ofclock
andetime
. Theclock
function is based on the system time, which can be adjusted periodically by the operating system, and thus might not be reliable in time comparison operations.To return a datetime scalar representing the current date and time, type:
t = datetime('now')