String to Datenum Format using opts and Setvaropts

3 ビュー (過去 30 日間)
Xymbu
Xymbu 2020 年 9 月 21 日
回答済み: Star Strider 2020 年 9 月 21 日
I have read in a table using readtable() and am trying to convert on of the columns to datetime as it is currently a string in the format of the data.
My datetime format looks like...
20200721T145002Z
in which the format looks like yyyyMMdd'T'HHmmss'Z'
when i try to use
opts = setvaropts(opts, 'time','DatetimeFormat', 'yyyyMMdd HHmmss ');
or any combination with the T and Z markers it kicks back an error.
Im not an expert with how i need to format this so any help would be appreciated.

採用された回答

Star Strider
Star Strider 2020 年 9 月 21 日
Try reading those in as strings, then doing the conversion later:
t = repmat('20200721T145002Z', 5, 1); % Create Data
T1 = table(compose('%s',t)); % Create Table
T1.Var1 = datetime(T1{:,1}, 'InputFormat','uuuuMMdd''T''HHmmssZ','TimeZone','UTC') % Convert To Datetime
Alternatively, you can try it with setvaropts, using the 'InputFormat' string I use here. If that does not work, read it in as a string and then do the converstion.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by