convert Modified Julian Date

13 次查看(过去 30 天)
I am importing a .dat file that has MJD in the form of "55743.21235" and if converted in Excel (by taking the cell-50813) is 06/30/11 05:05:47. This is cummlative file with years worth of data but each quarter, I am only interested in the current quarter(i.e. Oct 01, 2011-Dec 31, 2011).
How can I convert/change each of the MJDs (in a single column of over +1000 MJDs) that I import into the more meaningful form of 'dd:mmm:yyyy' or 'mmm:dd:yyyy'? Once the conversion is complete, the user will be queried to select a time frame, or quarter, of interest. The HH:MM:SS aren't required. Thanks, Kate

采纳的回答

Walter Roberson
Walter Roberson 2011-11-15
The difference between datenum('06/30/11 05:05:47') (your proposed translation) and 55743.21235, is 678941
However, datenum('Nov 17, 1858,00:00') is 678942, which is a one day difference compared to your proposal.
The Nov 17, 1858 00:00 date is listed in Wikipedia, and the 678942 offset is exactly that needed to properly convert the example MJD 49987 to September 27, 1995, as documented in the US Naval Observatory web site
The evidence would seem to suggest that your calculations are off by exactly one day, and that Fangjun's calculations are correct.
  1 个评论
Kate L.
Kate L. 2011-11-16
works perfectly...thank you!
mjd = data(1:end,1) %mjd in the form 55743.21235
mjdconv = mjd+678942
datestr(mjdconv)

请先登录,再进行评论。

更多回答(1 个)

Fangjun Jiang
Fangjun Jiang 2011-11-14
You can use datestr(),datenum() and datevec() function. Try this:
a=now;
b=datestr(a)
c=datevec(a)
According to Wikipedia, http://en.wikipedia.org/wiki/Julian_day, the epoch (commencing time) of MJD is 00:00 November 17, 1858, Wednesday. So,
d = 55743.21235;
MJD_epoch='Nov 17, 1858,00:00';
datestr(d+datenum(MJD_epoch))
ans =
01-Jul-2011 05:05:47
I am not sure why it's still off one day (according to you). Are you sure you got the correct day?
  3 个评论
Fangjun Jiang
Fangjun Jiang 2011-11-14
You mentioned an offset of 50813?
a=55743.21235;
b=a-50813;
datestr(a)
datestr(b)
Fangjun Jiang
Fangjun Jiang 2011-11-14
datestr() and datenum() can specify pivot year too. See the document.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by