I want to convert my Julian date number into normal date that is UTC date format in JavaScript . For an example I have Julian number "57115". I want to convert in format like 10 April,2015.
问问题
2766 次
3 回答
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)));
于 2015-04-14T12:58:05.797 回答
1
2015 年 4 月值为 57,115 的著名日期编号方法是修改儒略日期 (MJD)。它是自公历日期 1858 年 11 月 17 日世界标准时间 (UT) 开始时的午夜以来的天数。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 来源的日期对象。1858 年 11 月 17 日星期三 00:00:00 GMT 应该是 1858 年 11 月 17 日星期三 00:00:00 UT。
输入 MJD 为 57115。等效的公历日期和时间为 Fri, 03 Apr 2015 00:00:00 GMT。
于 2015-05-21T13:40:34.637 回答
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)
于 2015-04-14T12:44:36.677 回答