我想将我的Julian日期编号转换为JavaScript中的UTC日期格式的正常日期 。举个例子,我有朱利安数字" 57115 "。我希望转换为 2015年4月10日。
答案 0 :(得分:1)
尝试以下代码
var X = parseFloat(57115)+0.5;
var Z = Math.floor(X); //Get day without time
var F = X - Z; //Get time
var Y = Math.floor((Z-1867216.25)/36524.25);
var A = Z+1+Y-Math.floor(Y/4);
var B = A+1524;
var C = Math.floor((B-122.1)/365.25);
var D = Math.floor(365.25*C);
var G = Math.floor((B-D)/30.6001);
//must get number less than or equal to 12)
var month = (G<13.5) ? (G-1) : (G-13);
//if Month is January or February, or the rest of year
var year = (month<2.5) ? (C-4715) : (C-4716);
month -= 1; //Handle JavaScript month format
var UT = B-D-Math.floor(30.6001*G)+F;
var day = Math.floor(UT);
//Determine time
UT -= Math.floor(UT);
UT *= 24;
var hour = Math.floor(UT);
UT -= Math.floor(UT);
UT *= 60;
var minute = Math.floor(UT);
UT -= Math.floor(UT);
UT *= 60;
var second = Math.round(UT);
alert(new Date(Date.UTC(year, month, day, hour, minute, second)));
答案 1 :(得分:1)
2015年4月具有57,115值的众所周知的日编号方法是修改后的Julian日期(MJD)。它是公历时间(UT)1855年11月17日格里高利历年初午夜以来的天数。 UT是过时缩写GMT的继承者。 MJD总是在UT。一天中的时间可以表示为一天的一小部分,因此MJD 0.75将是1858年11月17日18:00,UT。我会忽略UT和UTC之间长达一秒左右的微妙差异,因为流行的个人计算设备最多只能精确到几秒钟。以下是利用内置Date对象进行转换的示例。
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<HTML>
<BODY>
<pre>
<script language="JavaScript">
// Origin of Modified Julian Date (MJD) is 00:00 November 17, 1858 of
// the Gregorian calendar
// Internal JavaScript built in Date object internal time value 0
//milliseconds (ms) is 00:00 January 1, 1970, UT,
// equal to MJD 40587
// Internal value of MJD origion should be
//negative 40587 days * 86,400,000 milliseconds per day =
// 3,506,716,800,000 ms
var originMJD = -3506716800000;
document.write("Test creation of date object containing origin of MJD.");
document.write(new Date(-3506716800000).toUTCString());
document.writeln(" should be Wed, 17 Nov 1858 00:00:00 UT.");
//Given an MJD display the Gregorian calendar date and time.
var inMJD = 57115;
var inInternal = (inMJD * 86400000) + originMJD;
document.writeln();
document.writeln("Input MJD is ", inMJD, ".");
document.write("Equivalent Gregorian calendar date and time is ",
new Date(inInternal).toUTCString(), ".");
</script>
</pre>
</BODY>
</HTML>
示例的输出应为:
测试创建日期对象,其中包含MJD.Wed的来源,1858年11月17日00:00:00 GMT应于1858年11月17日星期三00:00:00 UT。
输入MJD是57115。 等效公历日期和时间是格林威治标准时间2015年4月3日00:00:00。
答案 2 :(得分:0)
这是公式:
Q = JD+0.5
Z = Integer part of Q
W = (Z - 1867216.25)/36524.25
X = W/4
A = Z+1+W-X
B = A+1524
C = (B-122.1)/365.25
D = 365.25xC
E = (B-D)/30.6001
F = 30.6001xE
Day of month = B-D-F+(Q-Z)
Month = E-1 or E-13 (must get number less than or equal to 12)
Year = C-4715 (if Month is January or February) or C-4716 (otherwise)