Convert time column from hours to ddmmmyyyy HH:MM:SS

1 回表示 (過去 30 日間)
Phoebe Armitage
Phoebe Armitage 2020 年 11 月 5 日
コメント済み: Peter Perkins 2020 年 11 月 20 日
My time column is in hours (0000 01JAN1900=0hr) and starts from 999,312h (meaning 0000 01JAN2014). How would I convert a column vector of times (hrs) into a column of time in ddmmmyyyy HH:MM:SS format?
  1 件のコメント
KSSV
KSSV 2020 年 11 月 5 日
Read about datetime.

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

採用された回答

Stephen23
Stephen23 2020 年 11 月 5 日
編集済み: Stephen23 2020 年 11 月 5 日
dth = 999312 + [0;1;12;24;36;42;31*24] % fake data
dth = 7×1
999312 999313 999324 999336 999348 999354 1000056
dtm = datetime(dth*60*60, 'ConvertFrom','epochtime','Epoch','1900-01-01', 'Format','ddMMMyyyy HH:mm:ss')
dtm = 7×1 datetime array
01Jan2014 00:00:00 01Jan2014 01:00:00 01Jan2014 12:00:00 02Jan2014 00:00:00 02Jan2014 12:00:00 02Jan2014 18:00:00 01Feb2014 00:00:00
  7 件のコメント
Phoebe Armitage
Phoebe Armitage 2020 年 11 月 5 日
Ahh! I just used readtable - much simpler thank you!
Peter Perkins
Peter Perkins 2020 年 11 月 20 日
Just to be clear: "whereas MATLAB counts days from day zero of year zero" refers to the older way of working with dates/times in MATLAB. The newer better way to do it is, as Stephen says, datetime, which doesn't work like that. datetime has been around since R2014b.

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

その他の回答 (1 件)

Steven Lord
Steven Lord 2020 年 11 月 5 日
dth = 999312 + [0;1;12;24;36;42] % fake data
start = datetime(1900, 1, 1);
dates = start + hours(dth)

カテゴリ

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