将常规日期和时间转换为Julian日期,反之亦然

时间:2014-05-30 03:11:40

标签: java date julian-date

我目前正在开发一个计算日出和日落时间的程序。我怎么能把yyyymmddhhmmss转换成Julian日期?我需要日期非常精确。如果有这样的转换的例子,那就太好了。朱利安日期代码:

        Calendar cNow = Calendar.getInstance();
        Calendar cJan1 = Calendar.getInstance();

        double julianJan1_2014_12_00_00 = 2456659;
        cJan1.set(2014, 0, 0, 12, 0);
        Date dJan1 = cJan1.getTime();
        Date dNow = cNow.getTime();
        long lJan1 = dJan1.getTime();
        long lNow = dNow.getTime();
        double diffDay = (lNow - lJan1) / 1000 / 60 / 60 / 24;
        double julianDate = diffDay + julianJan1_2014_12_00_00;

日出和日落代码(来自维基百科的公式):

        Calendar cNow = Calendar.getInstance();
        Calendar cJan1 = Calendar.getInstance();

        double julianJan1_2014_12_00_00 = 2456659;
        cJan1.set(2014, 0, 0, 12, 0);
        Date dJan1 = cJan1.getTime();
        Date dNow = cNow.getTime();
        long lJan1 = dJan1.getTime();
        long lNow = dNow.getTime();
        double diffDay = (lNow - lJan1) / 1000 / 60 / 60 / 24;
        double julianDate = diffDay + julianJan1_2014_12_00_00;

        double nStar = julianDate - 2451545.0009 - (-longi) / 360;
        double n = nStar + 0.5;
        double jStar = 2151545.0009 + (-longi) / 360 + n;
        double M = (357.5291 + 0.98560028 * (jStar - 2451545)) % 360;       
        double C = 1.9148 * Math.sin(M/57.3) + 0.0200 * Math.sin(2 * M/57.3) + 0.0003 * Math.sin(3 * M/57.3);   
        double eclipLong = (M + 102.9372 + C + 180) % 360;
        double jTrans = jStar + 0.0053 * Math.sin(M/57.3) - 0.0069 * Math.sin(2 * eclipLong/57.3);
        double sinDecSun = Math.sin(eclipLong/57.3) * Math.sin(23.45/57.3);
        double cosHrAn = Math.sin(-0.83/57.3) - Math.sin(lat/57.3) * sinDecSun;
        double sunSet = 2451545.0009 + (Math.acos(cosHrAn/57.3) + (-longi)) / 360 + n + 0.0053 * Math.sin(M/57.3) - 0.0069 * Math.sin(2 * eclipLong/57.3);
        double sunRise = jTrans - (sunSet - jTrans);
        sunrise = sunRise;
        sunset = sunSet;

1 个答案:

答案 0 :(得分:0)

试试这个

    GregorianCalendar c = new GregorianCalendar();
    c.setGregorianChange(new Date(System.currentTimeMillis() + 100000000));
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd mm:HH:ss");
    df.setCalendar(c);
    String d = df.format(new Date());