This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Current date and time as date vector


c = clock
[c tf] = clock



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.


collapse all

To return the current date and time, use the clock function. Set the output format so that floating-point values display with up to five digits.

format shortg
c = clock
c = 1×6

         2019            4           13            0            6       19.455

The sixth element of the date vector output (seconds) is accurate to several digits beyond the decimal point.

To round to integer display format, use the fix function.

ans = 1×6

        2019           4          13           0           6          19

To test whether the current date and time occur during Daylight Saving Time (DST), use the second output of the clock function. tf is 1 (true) if c occurs during DST, and 0 (false) otherwise.

format shortg
[c tf] = clock
c = 1×6

         2019            4           13            0            8       28.172

tf = logical


  • MATLAB Online returns current Coordinated Universal Time (UTC) rather than local time.


  • To time the duration of an event, use the timeit or tic and toc functions instead of clock and etime. The clock 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')

See Also

| | | | | | | |

Introduced before R2006a