converting csv timestamp to datetime on import
14 次查看(过去 30 天)
显示 更早的评论
I have a CSV that has two columns, Date and Time. The general format of the text is colum 1, Date, is m/DD/YYYY, and column2, Time, is HH:mm:ss SSS. However, the output device outputs the text for time omitting the zero in cases where the digit is not bordered by other numbers in its value category. For example, one case reads out:
HH:m:ss S (11:1:30 1)
when it should read HH:mm:ss SSS (11:01:30 001) if it generated equal length strings.
I cannot change the output device to correct this to always include 'HH:mm:ss SSS' to perform a simple string input to use in the datetime(DateStrings,'InputFormat',infmt) method as the string changes length.
0 个评论
采纳的回答
Stephen23
2022-6-28
type test.csv
T = readtable('test.csv','Format','%{M/d/y}D%T%d','Delimiter',{',',' '})
D = T.Var1 + T.Var2 + milliseconds(T.Var3);
D.Format = 'yyyy-MM-dd HH:mm:ss.SSS'
2 个评论
Stephen23
2022-6-29
The READTABLE documentation states for the FORMAT that "The conversion specifiers are the same as the specifiers accepted by the textscan function", so this would be the resource to read:
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!