How to transform a cell array, which contains dates but not in the datetime format, into datetime array
2 次查看(过去 30 天)
显示 更早的评论
Hello to everybody.
The cell array contains values like this one :
x={'1991-01-09T02:00:00+00:00' ; '1991-01-09T03:00:00+00:00' ; '1991-01-09T04:00:00+00:00 .......}
and they are always in this format.
My goal is to obtain a hourly datetime array from it in the format 'yyyy-MM-dd''T''HH' or something similar, what's important is that it has also hours, i don't absolutely need minutes and seconds, just hours.
I need this solution because the cell array comes from an external textfile (it is a simulation output), and the dates in it are not everywhere perfectly regular hour by hour, so i don't need to just create a hourly datetime array myself, but i really would like to scan that cell array in some way and create a datetime array with the ones present in the original with years-months-days and hours.
Hope that my question is clear! Thank you!
0 个评论
采纳的回答
dpb
2021-1-29
编辑:dpb
2021-1-29
>> dt=datetime(tstr,'InputFormat','yyyy-MM-dd''T''hh:mm:ssXXX','TimeZone','America/Chicago')
dt =
3×1 datetime array
08-Jan-1991 20:00:00
08-Jan-1991 21:00:00
08-Jan-1991 22:00:00
>>
Fixup the time zone to match or convert to be unzoned by setting its 'TimeZone' property to '' (empty string).
>> dt.TimeZone=''
dt =
3×1 datetime array
08-Jan-1991 20:00:00
08-Jan-1991 21:00:00
08-Jan-1991 22:00:00
>>
Set format as want via:
>> dt.Format='dd-MMM-uuuu HH'
dt =
3×1 datetime array
08-Jan-1991 20
08-Jan-1991 21
08-Jan-1991 22
>>
2 个评论
更多回答(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!