How do I convert a string to a date?

3 ビュー (過去 30 日間)
ARGY B
ARGY B 2019 年 8 月 14 日
コメント済み: Star Strider 2019 年 8 月 15 日
I have a txt file with dates in the following form:
200309302300
200309302310
200309302320
......etc
How can I convert these strings into date form?
something like : 2003-Sep-30 23:00 or 2003-09-30 23:00

採用された回答

Star Strider
Star Strider 2019 年 8 月 14 日
I am not certain if the numbers are themselves strings, or numbers.
If they are numbers, this works:
numdate = [200309302300
200309302310
200309302320];
dn = datenum(num2str(numdate), 'yyyymmddHHMM') % Date Numbers
dv = datevec(dn)
dt = datetime(num2str(numdate), 'InputFormat','yyyyMMddHHmm') % ‘datetime’ Array
If they are strings, omit the str2num calls and just insert them directly.
  2 件のコメント
ARGY B
ARGY B 2019 年 8 月 15 日
Thank you :)
Star Strider
Star Strider 2019 年 8 月 15 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by