- UTC(Universal Time, Co-ordinated) :世界协调时间
- MJD(Modified Julian Date): 简化的儒略日
- JD(Julian Day):儒略日
连续纪日的儒略日(JD):以儒略历公元前4713年1月1日的GMT正午为第0日的开始。
简化儒略日(MJD): MJD=JD-2400000.5 MJD的第0日是从公历1858年11月17日的GMT零时开始的。
在线计算MJD(十进制):http://www.csgnetwork.com/julianmodifdateconv.html
十进制转十六进制:https://www.rapidtables.com/convert/number/decimal-to-hex.html
计算MJD时间的C++代码:
#include <bits/stdc++.h>
using namespace std;
//年月日 转 mjd
long cal_mjd(int y, int m, int d) {
//计算出儒略日
int jd = (d - 32075 + 1461 * (y + 4800 + (m - 14) / 12) / 4 + 367 * (m - 2 - (m - 14) / 12 * 12) / 12 -
3 * ((y + 4900 + (m - 14) / 12) / 100) / 4);
//简化儒略日,其定义为:
//MJD=JD-2400000.5
int mjd = jd - 2400000.5;
return mjd;
}
//mjd 转 年月日
void MJD2YMD(long MJD) {
int year, month, day;
short K;
short dayInMonth[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
year = ((MJD) * 100 - 1507820) / 36525;
month = ((MJD) * 10000 - 149561000 - year * 36525 / 100 * 10000) / 306001;
day = (MJD) - 14956 - (year * 36525) / 100 - (month * 306001) / 10000;
if (month == 14 || month == 15) {
K = 1;
} else {
K = 0;
}
year = year + K;
month = month - 1 - K * 12;
//瑞年判断
if ((year % 4 == 0) && (year % 400 != 0)) {
dayInMonth[2] = 29;
}
if (day > dayInMonth[month]) {
day -= dayInMonth[month];
month += 1;
if (month > 12) {
month -= 12;
year += 1;
}
}
int Y = year + 1900;
int M = month;
int D = day;
cout << "year = " << Y << " Month = " << M << " Day = " << D << endl;
return;
}
string DecIntToHexStr(long num) {
string str;
long tmp = num / 16;
int left = num % 16;
if (tmp > 0)
str += DecIntToHexStr(tmp);
if (left < 10)
str += (left + '0');
else
str += ('A' + left - 10);
return str;
}
int main() {
long mjd = cal_mjd(2019, 6, 13);
cout << "get MJD:" << mjd << endl;
string hexstr=+"0x"+DecIntToHexStr(mjd);
cout << "MJD = "<< mjd << ",MJD to hex is :" << hexstr << endl;
cout << "MJD to Date:";
MJD2YMD(mjd);
return 0;
}