Documentation

clock

Current date and time as date vector

Syntax

c = clock
[c tf] = clock

Description

example

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

[year month day hour minute seconds]

Theclockfunction calculates the current date and time from the system time.

example

[c tf] = clockreturns a second output argument that is1(true) if the current date and time occur during Daylight Saving Time (DST) in your system's time zone, and0(false) otherwise.

Examples

collapse all

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

formatshortgc = clock
c = 2017 9 19 19 10 16.538

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 thefixfunction.

fix(c)
ans = 20179 19 19 10 16

To test whether the current date and time occur during Daylight Saving Time (DST), use the second output of theclockfunction.tfis1(true) ifcoccurs during DST, and0(false) otherwise.

formatshortg[c tf] = clock
c = 2017 9 19 19 23 24.826
tf =logical1

Tips

  • To time the duration of an event, use thetimeitorticandtocfunctions instead ofclockandetime. Theclockfunction 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')

Introduced before R2006a

Was this topic helpful?