How to get Matlab to recognize a number string as a date?

8 ビュー (過去 30 日間)
Sarah
Sarah 2011 年 9 月 1 日
コメント済み: Walter Roberson 2018 年 6 月 18 日
Hello everyone,
I am trying to write a Matlab script to automatically update dates within a .txt file. I have a 16 digit number string in the format of yyyymmddhhmmss and I need to get Matlab to read and interpret this number as a date. When I try datenum, datestr, or datevec Matlab doesn't seem to be recognizing the format.
When I use read through the help for the datestr, the closest preset format is yyyymmddTHHMMSS but when I simply add a T to my number string, it is still not recognized.
Any help would be really appreciated as I have been pulling my hair out over this for days. Thanks a lot!
~Sarah :)
  1 件のコメント
Sarah
Sarah 2011 年 9 月 1 日
I am able to pull the information from the text file and have matlab read it as a string, it is just not recognizing it as a date.

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

採用された回答

Walter Roberson
Walter Roberson 2011 年 9 月 1 日
datenum(YourString,'yyyymmddHHMMSS')
  2 件のコメント
Sarah
Sarah 2011 年 9 月 1 日
Thank you, the issue was that I did not capitalize the latter portion of the command. I appreciate the help.
newtomatlab
newtomatlab 2016 年 1 月 1 日
That is indeed very helpful.Thanks!

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

その他の回答 (1 件)

Sean de Wolski
Sean de Wolski 2011 年 9 月 1 日
doc datenum
& friends
  4 件のコメント
JAMES MAINA
JAMES MAINA 2018 年 6 月 18 日
編集済み: Walter Roberson 2018 年 6 月 18 日
can anyone also assist me how to get date and time from the following
"04.10.201714:20:13:730"
"04.10.201714:20:13:831"
"04.10.201714:20:13:930"
"04.10.201714:20:14:031"
"04.10.201714:20:14:131"
"04.10.201714:20:14:230"
"04.10.201714:20:14:331"
"04.10.201714:20:14:430"
"04.10.201714:20:14:530"
"04.10.201714:20:14:631"
it is in form of month.date.year.time
Walter Roberson
Walter Roberson 2018 年 6 月 18 日
Is that a string() array? Is it a cell array of character vectors each of which happens to begin and end with double-quote? Is that entries in a text file?
If S is a cell array of character vectors that have literal " inside them, then:
datetime(S, 'InputFormat', '"MM.dd.yyyyHH:mm:ss:SSS"')

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

カテゴリ

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