How to count the number of hours with reference to a MATLAB formatted date?

4 ビュー (過去 30 日間)
Ashish
Ashish 2014 年 8 月 20 日
コメント済み: Ashish 2014 年 8 月 20 日
Using MATLAB datenum function, one can generate date patterns like 7.3560e+05. This represents 03-Jan-2014 02:00:00.
If I want to count the number of hours (for e.g. in this case: 50 hrs) of this number from 01-Jan-2013 00:00:00, how can I do it? I want to generalize for any datenum formatted date.
Thanks.

採用された回答

Joseph Cheng
Joseph Cheng 2014 年 8 月 20 日
the number returned from datenum is in days. so if we go
time1 = datenum(datestr(now));
pause(1);
time2 = datenum(datestr(now));
deltaTime = (time2-time1)*24*60*60
then we should get deltaTime = 1 (second). So to count the hours we can go
time1 = datenum(datestr(now));
current_time = datestr(time1)
twodayslater = datestr(time1+50/24)
such that the 50 hours later is 2days 2 hours so we can see that when comparing the current_time to twodayslater.
  2 件のコメント
Joseph Cheng
Joseph Cheng 2014 年 8 月 20 日
so for your arbitrary datestr formatted date you can go
datestr(datenum(' 01-Jan-2013 00:00:00') +50/24)
As long as your date string is accepted into datenum you can go back and forth.
Ashish
Ashish 2014 年 8 月 20 日
Thanks Joseph for the detailed explanation. Certainly helped.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by