How to transform a cell array, which contains dates but not in the datetime format, into datetime array
3 ビュー (過去 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!