Info

この質問は閉じられています。 編集または回答するには再度開いてください。

atypical date string to datenum conversion

1 回表示 (過去 30 日間)
Chris O'Donnell
Chris O'Donnell 2018 年 2 月 22 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hi,
Can anyone suggest how to convert the following date string to a datenum or datetime?
'16/10/2017 11:50'
Thanks!

回答 (1 件)

KSSV
KSSV 2018 年 2 月 22 日
str = datetime('16/10/2017 11:50') ;
datenum(str)
  1 件のコメント
Steven Lord
Steven Lord 2018 年 2 月 22 日
The one-input datetime call could issue a warning if the input format of the text representation of your date and time can't be unambiguously determined (like '05/10/2017 11:50' -- is that October 5th or May 10th?) In that case, avoid that ambiguity by specifying an 'InputFormat'.
This is October 16th.
>> dt = datetime('16/10/2017 11:50', ...
'InputFormat', 'dd/MM/yyyy HH:mm')
dt =
datetime
16-Oct-2017 11:50:00
Here's how to distinguish between October 5th and May 10th
>> dt = datetime('05/10/2017 11:50', ...
'InputFormat', 'dd/MM/yyyy HH:mm')
dt =
datetime
05-Oct-2017 11:50:00
>> dt = datetime('05/10/2017 11:50', ...
'InputFormat', 'MM/dd/yyyy HH:mm')
dt =
datetime
10-May-2017 11:50:00

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by