1 | function [year, month, day, hour, minute, second] = mjd2date(mjd) |
---|
2 | %MJD2DATE Gregorian calendar date from Julian day number. |
---|
3 | % |
---|
4 | % [YEAR, MONTH, DAY, HOUR, MINUTE, SECOND] = MJD2DATE(MJD) returns the |
---|
5 | % Gregorian calendar date (year, month, day, hour, minute, and second) |
---|
6 | % corresponding to the Julian day number JDAY. |
---|
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-03-03 12:50:30 +0100 |
---|
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 | % We could have got everything by just using |
---|
30 | % |
---|
31 | % jd = mjd2jd(mjd); |
---|
32 | % [year, month, day, hour, minute, second] = jd2date(jd); |
---|
33 | % |
---|
34 | % but we lose precision in the fraction part when MJD is converted to JD |
---|
35 | % because of the large offset (2400000.5) between JD and MJD. |
---|
36 | |
---|
37 | jd = mjd2jd(mjd); |
---|
38 | [year, month, day] = jd2date(jd); |
---|
39 | |
---|
40 | if nargout > 3 |
---|
41 | fmjd = mjd - floor(mjd); |
---|
42 | [hour, minute, second] = days2hms(fmjd); |
---|
43 | end |
---|