how to use datetime(datestr)

10 次查看(过去 30 天)
zhize lee
zhize lee 2020-8-9
Dear all, I tried to convert the matlab serial dates (vector) back to a date string . I use matlab2016b. The data and codein the attached file.
And the error is:
Could not recognize the format of the date/time text. You can specify a format character vector using the 'InputFormat' parameter.
If the date/time text contain day, month, or time zone names in a language foreign to the 'zh_CN' locale, those might not be
recognized. You can specify a different locale using the 'Locale' parameter.
Error in test (line 2)
Time = datetime(datestr((DATA(:,1)+datenum('12/31/1899','mm/dd/yy'))));time_num is a vector of serial dates. I have attached the file please.
Thank you very much!

回答(1 个)

Walter Roberson
Walter Roberson 2020-8-9
Do not try to mix serial data numbers and datetime objects.
You can skip most of your problems.
t = readtable('data.xlsx');
Time = t{:,1};
Time will already be in datetime format, having been automatically converted from Excel date format.
  8 个评论
zhize lee
zhize lee 2020-8-12
but, how can just change the code with the original form.Thank you!
Walter Roberson
Walter Roberson 2020-8-12
With the posted code, you can just use what I posted already,
t = readtable('data.xlsx');
Time = t{:,1};
You have not posted any code beyond that, and any code beyond that would have to be using datestr() if it wanted datestr because your current code is already generating datetime objects.
can you give me your email
Sorry, I work with code that is posted in public. I do not read most of the code that is sent to me in email; I either let it sit without response, or else I tell the person that they need to post it in public if they want a response from me (unless they want to hire me.)

请先登录,再进行评论。

类别

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