gpt4 book ai didi

javascript - 在javascript中将朱利安日期数字转换为正常日期(utc)

转载 作者:行者123 更新时间:2023-11-30 16:56:30 25 4
gpt4 key购买 nike

我想将我的 Julian 日期数字转换为普通日期,即 JavaScript 中的 UTC 日期格式.例如,我有儒略数“57115”。我想转换为 2015 年 4 月 10 日之类的格式。

最佳答案

试试下面的代码

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)));

关于javascript - 在javascript中将朱利安日期数字转换为正常日期(utc),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29627533/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com