Documentation

This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

clock

Current date and time as date vector

Syntax

Description

example

c = clock returns a six-element date vector containing the current date and time in decimal form:

[year month day hour minute seconds]

Examples

collapse all

Use clock to return the current date and time.

format shortg
c = clock
c =

         2016           10            4           21            9       42.407

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

Use the fix function to round to integer display format.

fix(c)
ans =

        2016          10           4          21           9          42

More About

collapse all

Tips

  • 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

Was this topic helpful?