What is the equivalent datetime() call to the clock() function?

I have some code from 2010 that uses clock(), which is not recommended in R2022b. clock() returns an array of double. How can I get this result by using datetime()? I don't see any examples that do this. For example,
c = clock
c is [2024 4 5 10 47 21.9]

 採用された回答

Stephen23
Stephen23 2024 年 4 月 15 日
編集済み: Stephen23 2024 年 4 月 16 日

0 投票

Note that DATETIME is an object with properties, so (depending on your requirements) accessing its properties is a simple option that does not require calling any other functions:
dt = datetime('now')
dt = datetime
15-Apr-2024 21:23:12
dt.Year
ans = 2024
dt.Month
ans = 4
dt.Day
ans = 15
dt.Hour
ans = 21
dt.Minute
ans = 23
dt.Second
ans = 12.2519

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeDates and Time についてさらに検索

製品

リリース

R2022b

質問済み:

2024 年 4 月 5 日

編集済み:

2024 年 4 月 16 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by