1 | function [year, month, day, hour, minute, second] = jd2date(jd) |
---|
2 | %JD2DATE Gregorian calendar date from modified Julian day number. |
---|
3 | % |
---|
4 | % [YEAR, MONTH, DAY, HOUR, MINUTE, SECOND] = JD2DATE(JD) returns the |
---|
5 | % Gregorian calendar date (year, month, day, hour, minute, and second) |
---|
6 | % corresponding to the Julian day number JD. |
---|
7 | % |
---|
8 | % Start of the JD (Julian day) count is from 0 at 12 noon 1 JAN -4712 |
---|
9 | % (4713 BC), Julian proleptic calendar. Note that this day count conforms |
---|
10 | % with the astronomical convention starting the day at noon, in contrast |
---|
11 | % with the civil practice where the day starts with midnight. |
---|
12 | % |
---|
13 | % Astronomers have used the Julian period to assign a unique number to |
---|
14 | % every day since 1 January 4713 BC. This is the so-called Julian Day |
---|
15 | % (JD). JD 0 designates the 24 hours from noon UTC on 1 January 4713 BC |
---|
16 | % (Julian calendar) to noon UTC on 2 January 4713 BC. |
---|
17 | |
---|
18 | % Sources: - http://tycho.usno.navy.mil/mjd.html |
---|
19 | % - The Calendar FAQ (http://www.faqs.org) |
---|
20 | |
---|
21 | % Author: Peter John Acklam |
---|
22 | % Time-stamp: 2002-05-24 15:24:45 +0200 |
---|
23 | % E-mail: pjacklam@online.no |
---|
24 | % URL: http://home.online.no/~pjacklam |
---|
25 | |
---|
26 | nargsin = nargin; |
---|
27 | error(nargchk(1, 1, nargsin)); |
---|
28 | |
---|
29 | % Adding 0.5 to JD and taking FLOOR ensures that the date is correct. |
---|
30 | % Here are some sample values: |
---|
31 | % |
---|
32 | % MJD Date Time |
---|
33 | % -1.00 = 1858-11-16 00:00 (not 1858-11-15 24:00!) |
---|
34 | % -0.75 = 1858-11-16 06:00 |
---|
35 | % -0.50 = 1858-11-16 12:00 |
---|
36 | % -0.25 = 1858-11-16 18:00 |
---|
37 | % 0.00 = 1858-11-17 00:00 (not 1858-11-16 24:00!) |
---|
38 | % +0.25 = 1858-11-17 06:00 |
---|
39 | % +0.50 = 1858-11-17 12:00 |
---|
40 | % +0.75 = 1858-11-17 18:00 |
---|
41 | % +1.00 = 1858-11-18 00:00 (not 1858-11-17 24:00!) |
---|
42 | |
---|
43 | ijd = floor(jd + 0.5); % integer part |
---|
44 | |
---|
45 | if nargout > 3 |
---|
46 | fjd = jd - ijd + 0.5; % fraction part |
---|
47 | [hour, minute, second] = days2hms(fjd); |
---|
48 | end |
---|
49 | |
---|
50 | % The following algorithm is from the Calendar FAQ. |
---|
51 | |
---|
52 | a = ijd + 32044; |
---|
53 | b = floor((4 * a + 3) / 146097); |
---|
54 | c = a - floor((b * 146097) / 4); |
---|
55 | |
---|
56 | d = floor((4 * c + 3) / 1461); |
---|
57 | e = c - floor((1461 * d) / 4); |
---|
58 | m = floor((5 * e + 2) / 153); |
---|
59 | |
---|
60 | day = e - floor((153 * m + 2) / 5) + 1; |
---|
61 | month = m + 3 - 12 * floor(m / 10); |
---|
62 | year = b * 100 + d - 4800 + floor(m / 10); |
---|