フィルターのクリア

how can I add add sec, min and hours to time?

285 ビュー (過去 30 日間)
zeezo
zeezo 2017 年 11 月 10 日
編集済み: Felix Bl 2018 年 11 月 1 日
I want to add sec, min and hours to a time.
Example:
now it is 07:00:00 am and i would like to add 320 sec to be 07:05:20 am
I try "datenum" but this include a date which I don't want ?
  10 件のコメント
zeezo
zeezo 2017 年 11 月 13 日
Thank you Walter.
can you explain in more details?
Walter Roberson
Walter Roberson 2017 年 11 月 13 日
dt = datetime( '23:58:00', 'InputFormat', 'HH:mm:ss' );
dt.Format = 'HH:mm:ss';
dt + seconds(320)
ans =
datetime
00:03:20

サインインしてコメントする。

回答 (2 件)

KL
KL 2017 年 11 月 10 日
Use duration maybe,
>> t1 = duration([07 0 0])
t1 =
duration
07:00:00
>> t2 = t1+seconds(320)
t2 =
duration
07:05:20
  1 件のコメント
zeezo
zeezo 2017 年 11 月 13 日
編集済み: zeezo 2017 年 11 月 13 日
Thank you very much.
this does not recognize the duration as a hour for example
>> t1 = duration([23 58 0])
t1 =
23:58:00
>> t2 = t1+seconds(320)
t2 =
24:03:20
it add to the duration which makes it more than 23:59:59.
I want it to be 00:03:20

サインインしてコメントする。


Felix Bl
Felix Bl 2018 年 11 月 1 日
編集済み: Felix Bl 2018 年 11 月 1 日
This also works fine:
t1 = datestr(addtodate(datenum('07:00:00','HH:MM:SS'),320,'second'),'HH:MM:SS')

カテゴリ

Help Center および File ExchangeTime Series Objects についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by