Converting date into date and hours

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Dates and Time 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by