Separating a timestamp into individual components
4 ビュー (過去 30 日間)
古いコメントを表示
I have time stamps in a vector with the form DDMMYYYY. Is there any way to seperate all of the elements so I can have a date column DD, a month column MM and a year column YYYY for each individual row.
The first few lines of the vector are below:
times =
20082009
21082009
22082009
23082009
And I am trying to get it in the form below so each component of the time stamp and its corresponding data are set out in different columns.
20 08 2009
21 08 2009
22 08 2009
23 08 2009
I have tried some of the methods listed in similar threads but they didn't seem to work for this format. The times vector only includes a column of these timestamps with the corresponding data and the table headings removed.
0 件のコメント
回答 (1 件)
Chunru
2022 年 9 月 27 日
編集済み: Chunru
2022 年 9 月 27 日
times = [
20082009
21082009
22082009
23082009];
d = floor(times/1e6);
m = mod(floor(times/1e4), 100);
y = mod(times, 10000);
[d m y]
% alternatively use datetime
dt = datetime(string(times), "InputFormat", "ddMMyyyy");
dt
[day(dt), month(dt), year(dt)]
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Data Type Identification についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!