フィルターのクリア

Converting date into date and hours

1 回表示 (過去 30 日間)
zafar khan
zafar khan 2017 年 9 月 21 日
回答済み: Peter Perkins 2017 年 9 月 21 日
I have half hourly energy data and need to convert the date into hourly format. At present the date is dd/mm/yyyy and hour is 0.5,1.0,1.5,... I want to get it as yyyy-mm-dd HH:MM:SS Any idea how to do it??
  1 件のコメント
James Tursa
James Tursa 2017 年 9 月 21 日
Please be more specific. What is the exact format of your input data (the date and hour data)? Character string array and double array? Cell arrays? Or ...? And what do you want for the result ... a cell array of character strings? Or ...?

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

回答 (1 件)

Peter Perkins
Peter Perkins 2017 年 9 月 21 日
Use datetimes and durations:
>> t0 = datetime('today','Format','yyyy-MM-dd HH:mm:ss')
t0 =
datetime
2017-09-21 00:00:00
>> t = t0 + hours(0:.5:3)'
t =
7×1 datetime array
2017-09-21 00:00:00
2017-09-21 00:30:00
2017-09-21 01:00:00
2017-09-21 01:30:00
2017-09-21 02:00:00
2017-09-21 02:30:00
2017-09-21 03:00:00

カテゴリ

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