cell to string to date time
显示 更早的评论
I am importing a time from a .txt file. The import was auto-generated by matlab. The timestamp array is in this form: '2015-08-07 13:12:00' The variable is a 100x1 cell...I am not sure how to get the cell to a usable date time. Thank you.
...I can also import from the auto-generated import, however the import format does not match any of the available formats.
回答(2 个)
Walter Roberson
2015-8-16
datenum(TheCell)
to return the older serial datenum objects.
datetime(TheCell)
to return the newer datetime objects.
Peter Perkins
2015-8-18
Samantha, it sounds like you have code that you generated using the Import Tool. When you import a text file using the IT, you can specify that a particular column is datetime strings, and even specify a custom format for the strings. I cooked up a file with one column of numbers and one column of datetime strings, and the code I generated contains a line like
formatSpec = '%f%{yyyy-MM-dd HH:mm:ss}D%[^\n\r]';
That script/function will import that column as a datetime array. It's not clear if that's what you're looking to do.
类别
在 帮助中心 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!