![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1489937/image.png)
problem with datetime : day is wrong
1 次查看(过去 30 天)
显示 更早的评论
year=2008
month=2
day=31
hh =[ year month day ]
datetime(hh) %it's not correct ((correct day is 31 not 2)
%i try to change datetime default but the result is the same
datetime.setDefaultFormats('defaultdate','yyyy-MM-dd')
datetime(hh)
0 个评论
采纳的回答
Angelo Yeo
2023-9-22
There was no Feb 31st in 2008.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1489937/image.png)
4 个评论
Walter Roberson
2023-9-22
It is a common trick to code datetime([year 1 daynumber]) instead of datetime([year 1 1])+days(daynumber-1)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calendar 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!