how can i convert duration type to datetime type??

回答 (2 件)

SK
SK 2018 年 8 月 18 日

3 投票

duration is the difference between two datetime objects. So if you know a start date, you can add a duration to it to get the end date. So for example:
>> startdate = datetime(2000, 1, 1);
>> dur = duration(5000, 25, 0);
>> enddate = startdate + dur;
>> enddate
enddate =
datetime
27-Jul-2000 08:25:00
Peter Perkins
Peter Perkins 2018 年 8 月 24 日

1 投票

As posed, this question is equivalent to, "how do I convert 1 hour to a date?" As SK points out, you also have to answer, "1 hour from what?" And he's provided the solution.
Specific case: It may be that you have durations that represent times of day. If they are all today, for example, then
d = datetime('today') + dur;

カテゴリ

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

質問済み:

2018 年 8 月 18 日

回答済み:

2018 年 8 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by