Converting date into date and hours
2 次查看(过去 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
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
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!