Transforming an integer vector into dates text vector
23 次查看(过去 30 天)
显示 更早的评论
I am having a vector corresponding to dates in the following format yyyymmdd, ie for December 24th, 2010 it is 20101224. How can I transform this vector of integers into text dates in the following format 'mm-dd-yyyy'?
0 个评论
采纳的回答
Star Strider
2018-5-28
Assuming your original vector is numeric, there are two options:
dates = [20101224; 20101225; 20101226];
ds1 = datestr(datenum(num2str(dates), 'yyyymmdd'), 'mm-dd-yyyy'); % Use ‘datenum’ & ‘datestr’
ds2 = datetime(num2str(dates), 'InputFormat','yyyyMMdd', 'Format','MM-dd-yyyy'); % Use ‘datetime’
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!