How do you convert Month/Day to Julian Day?

11 ビュー (過去 30 日間)
Tom W
Tom W 2014 年 7 月 29 日
回答済み: Steven Lord 2016 年 11 月 10 日
I need to convert [yyyy MMM dd (hh mm ss)] into 3-digit (decimal) julian day, but every function I try takes numbers 1-31 (for dd "day") and doesn't increment the month, so julian day output is always less than 32. I need the ability to use the "MMM" portion...
I do not have major toolboxes (i.e. one solution requires the Financial Toolbox, not viable for me)
There is a solution I have by adding monthly # of days, but I'm not sure how to account for LEAP years (when # of days in February changes).
Output should be 001-365 (with floating decimal)

採用された回答

Tom W
Tom W 2016 年 11 月 10 日
I figured it out. Had to use:
julianday = hms2h(hr,min,sec) + day;
Can check by creating a matrix
greg2(julianday-1, year);

その他の回答 (2 件)

dpb
dpb 2014 年 7 月 29 日
>> dn=datenum(2008,1,[1:2:400].',0,0,0); % make up some date nums
>> d=dn-dn(1); % get the day from beginning
>> [d(1:10) d(180:189)] % display some results
ans =
0 358
2 360
4 362
6 364
8 366
10 368
12 370
14 372
16 374
18 376
>>
NB: datenum handles leap years transparently--2008 was selected specifically because it was a leap year; note that day 366 did show up.
This is cumulative over years as can be observed.
A handy little utility routine is
function is=isleapyr(yr) % returns T for given year being a leapyear
is=(datenum(yr+1,1,1)-datenum(yr,1,1))==366;
Put in m-file isleapyr.m and place on matlabpath

Steven Lord
Steven Lord 2016 年 11 月 10 日
Use the day method for datetime objects.
D = datetime('today')
DOY = day(D, 'dayofyear')
Since 2016 is a leap year and today is November 10th, DOY should be (and is) 315 according to Wikipedia.
datetime objects also have a juliandate method but that's slightly different.

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by