clock
(Not recommended; use datetime
) Current date and time as date
vector
clock
is not recommended. To return the current date and time as
a datetime
value, use datetime
instead. For more
information on updating your code, see Version History or Replace Discouraged Instances of Serial Date Numbers and Date Strings.
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.