How can I embed tab characters in datetime string formats?

8 ビュー (過去 30 日間)
Bruce Elliott
Bruce Elliott 2018 年 8 月 27 日
コメント済み: Bruce Elliott 2018 年 8 月 28 日
I have to create an output text file that will have lines of dates and times that are delimited by tab characters. I have no control over that format; it's a deliverable that has to be that way.
It looks like the .Format property of a datetime object cannot include escape characters, such as '\t'. Is there any easy way to get what I need, or must I assemble the output string piece-by-piece, using sprintf to insert the tab characters?
For reference, this is the format of a single line of the output, where the whitespace comes from tabs:
8 December 2015 14:10:50 8 December 2015 14:20:00

採用された回答

Stephen23
Stephen23 2018 年 8 月 28 日
編集済み: Stephen23 2018 年 8 月 28 日
Much more efficient than post-processing the dates is to just define the Format string using sprintf:
fmt = sprintf('d\tMMMM\tyyyy\tHH:mm:ss');
datetime(..., 'Format',fmt)
  1 件のコメント
Bruce Elliott
Bruce Elliott 2018 年 8 月 28 日
Ah ha! - That's exactly what I wanted, but I hadn't tried embedding the tab characters themselves into the format string. Thank you!

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

その他の回答 (1 件)

Bruce Elliott
Bruce Elliott 2018 年 8 月 27 日
Here's my own answer:
myString = regexprep(char(myDateTime),' ','\t');
That seems to work and isn't too painful, if you don't mind regular expressions.

カテゴリ

Help Center および File ExchangeString Parsing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by