Calculate the number of days in a year

8 次查看(过去 30 天)
FCC
FCC 2013-4-21
Is it possible to calculate the number of days in a year without having to put the year? If so how? Also i'm doing this on an m-file.

回答(2 个)

Royi Avital
Royi Avital 2013-4-21
I would go something like that:
firstDayInYear = '01/01/2012';
lastDayInYear = '31/12/2012';
firstDayInYearNum = datenum(firstDayInYear, 'dd/mm/yyyy');
lastDayInYearNum = datenum(lastDayInYear, 'dd/mm/yyyy');
numDaysInYear = lastDayInYearNum - firstDayInYearNum + 1;
That's it...

per isakson
per isakson 2013-4-21
Or one of
y = 2002;
datenum([y+1,1,1]) - datenum([y,1,1])
sum( eomday( y, [1:12] ) )

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by