フィルターのクリア

Info

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

Newbie question about date format

1 回表示 (過去 30 日間)
012786534
012786534 2016 年 5 月 16 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hi all, I have a 100 x 1 cell array with with a date format like 19-7-66 that I want to change into 19-September-1966. How would I do that? Thanks
  1 件のコメント
Guillaume
Guillaume 2016 年 5 月 16 日
Note that xx-7-xx is July not September!

回答 (2 件)

Steven Lord
Steven Lord 2016 年 5 月 16 日
Are the contents of your cell array datetime objects? If so take a look at the documentation for the Format property. If they are not datetime objects but just plain char vectors, consider converting them into datetime objects ( the documentation includes examples of how to convert a char vector into a datetime, including how to specify the format with which the char vector should be interpreted.)

Guillaume
Guillaume 2016 年 5 月 16 日
Assuming your cell array is an array of string, you would have to convert it first to datenum or datevec and then back to datestring, each time providing the correct format string:
datestr(datenum(yourcellarray, 'dd-mm-yy'), 'dd-mmm-yyyy')
However, I would recommend you actually convert your cell array to the newish datetime and stay with that. You can change the Format property of the datetime objects to display what you want (and use char to get a char array):
d = datetime(yourcellarray, 'InputFormat', 'dd-MM-yy'); %note that format strings for datetime differ from datestr
d.Format = 'dd-MMM-yyyy'
d %display d
char(d) %convert to char array

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by