Alex Rivera | Logout

Julian day of the year in Java

Asked 2010-06-09T12:03:34.507
28

I have seen the "solution" at http://www.rgagnon.com/javadetails/java-0506.html, but it doesn't work correctly. E.g. yesterday (June 8) should have been 159, but it said it was 245.

So, does someone have a solution in Java for getting the current date's three digit Julian day (not Julian date - I need the day this year)?

Thanks! Mark

Edit
Report

1 Answer

2

if we get a double julian date such as chordiant decision manager

http://java.ittoolbox.com/groups/technical-functional/java-l/java-function-to-convert-julian-date-to-calendar-date-1947446

The following is working but second is not taken care of How can I convert between a Java Date and Julian day number?

public static String julianDate(String julianDateStr) {

    try{
        // Calcul date calendrier Gr?gorien ? partir du jour Julien ?ph?m?ride 
        // Tous les calculs sont issus du livre de Jean MEEUS "Calcul astronomique" 
        // Chapitre 3 de la soci?t? astronomique de France 3 rue Beethoven 75016 Paris 
        // Tel 01 42 24 13 74 
        // Valable pour les ann?es n?gatives et positives mais pas pour les jours Juliens n?gatifs
        double jd=Double.parseDouble(julianDateStr);
          double z, f, a, b, c, d, e, m, aux;
            Date date = new Date();
            jd += 0.5;
            z = Math.floor(jd);
            f = jd - z;

            if (z >= 2299161.0) {
              a = Math.floor((z - 1867216.25) / 36524.25);
              a = z + 1 + a - Math.floor(a / 4);
            } else {
              a = z;
            }

            b = a + 1524;
            c = Math.floor((b - 122.1) / 365.25);
            d = Math.floor(365.25 * c);
            e = Math.floor((b - d) / 30.6001);
            aux = b - d - Math.floor(30.6001 * e) + f;
            Calendar calendar = new GregorianCalendar();
            calendar.setTime(date);
            calendar.set(Calendar.DAY_OF_MONTH, (int) aux);

            double hhd= aux-calendar.get(Calendar.DAY_OF_MONTH);                
            aux = ((aux - calendar.get(Calendar.DAY
answered 2011-08-25T16:43:15.320

Your Answer