Date Conversion Not Working Again

1 次查看(过去 30 天)
Chameleon17
Chameleon17 2017-11-14
评论: Chameleon17 2017-11-14
Hi, I'm sorry for posting a similar problem again - I keep encountering it and I'm not sure what i'm doing wrong. I simply want to upload a series of dates into MatLab but every time it goes through datnum to datestr the dates that come out are completely different to those I put in. I thought the problem last time might have been using excel to upload the data so now I'm only using text files. I have attached the bit of code and my input file - the first three dates I get back in the date string are - 04-Apr-2017, 06-Jul-2018, 06-Oct-2018. Any help or advice would be very much appreciated.
% Load OB Data
OB20172 = readtable('OB20176.txt');
% Create GS Time
datetime.setDefaultFormats('default','dd-MM-yyyy');
t1 = datetime(2017,04,1,0,0,0);
t2 = datetime(2017,10,31,8,0,0);
GS2017 = t1:t2;
%Convert OB Date
OBDates = OB20172;
OB2017 = table2array(OBDates);
OBDateNumbers = datenum(OB2017);
DateString = datestr(OBDateNumbers);
  1 个评论
Chameleon17
Chameleon17 2017-11-14
I figured it out - this can be deleted if this repetitive.
OB20172 = readtable('OB20176.txt','Format','%{dd/MM/yyyy}D','DateLocale','en_UK');

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by