clock - (Not recommended; use datetime) Current date and time as date

        vector - MATLAB ([original](https://in.mathworks.com/help/matlab/ref/clock.html)) ([raw](?raw))

Main Content

(Not recommended; use datetime) 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.

example

[c tf] = clock returns 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.

example

Examples

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.

c = 1×6

     2025            2            1            8            8       56.168

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

    2025           2           1           8           8          56

To determine if 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

     2025            2            1            8           23       58.628

Limitations

Tips

Extended Capabilities

expand all

Usage notes and limitations:

Version History

Introduced before R2006a

expand all

There are no plans to remove clock. However, the datetime function is recommended instead. The datetime data type provides flexible date and time formats, storage out to nanosecond precision, and properties to account for time zones and daylight saving time.

To return the current time as a datetime value, calldatetime. You can call it without any input arguments, or with "now" as the input argument.

d = datetime % or d = datetime("now")

d = datetime 15-Apr-2022 15:53:28

To return the current time as a date vector, split it apart using thedatevec function.