Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a Julian Date to Regular Calendar Date

How do I convert a 7-digit julian date into a format like MM/dd/yyy?

like image 620
Mark Acosta Avatar asked Jun 10 '10 19:06

Mark Acosta


People also ask

How do I convert a Julian date to a date in Excel?

In a blank cell, type this formula =TEXT(A1,"yy")&TEXT((A1-DATEVALUE("1/1/"&TEXT(A1,"yy"))+1),"000") and press Enter key, if you need you can apply this formula to a range by dragging the auto fill handle. Tip: A1 is the calendar date you want to convert to Julian date.

What is todays Julian date 2022?

Today's date is 08-Nov-2022 (UTC). Today's Julian Date is 22312 .


2 Answers

Found a useful site: http://www.rgagnon.com/javadetails/java-0506.html

This should do the trick:

 public static int[] fromJulian(double injulian) {

      int jalpha,ja,jb,jc,jd,je,year,month,day;
      double julian = julian + HALFSECOND / 86400.0;
      ja = (int) julian;
      if (ja>= JGREG) {    

       jalpha = (int) (((ja - 1867216) - 0.25) / 36524.25);
       ja = ja + 1 + jalpha - jalpha / 4;
       }
     jb = ja + 1524;
   jc = (int) (6680.0 + ((jb - 2439870) - 122.1) / 365.25);
   jd = 365 * jc + jc / 4;
   je = (int) ((jb - jd) / 30.6001);
   day = jb - jd - (int) (30.6001 * je);
   month = je - 1;
   if (month > 12) month = month - 12;
   year = jc - 4715;
   if (month > 2) year--;
   if (year <= 0) year--;

   return new int[] {year, month, day};
  }
like image 101
scott Avatar answered Nov 04 '22 19:11

scott


simple way is here and this will return approx 100% accurate information.

String getDobInfo(double doubleString){
        SweDate sweDate = new SweDate(doubleString);
        int year = sweDate.getYear();
        int month = sweDate.getMonth();
        int day = sweDate.getDay();
        // getting hour,minute and sec from julian date
        int hour = (int) Math.floor(sweDate.getHour());
        int min = (int) Math
                .round((sweDate.getHour() - Math.floor(hour)) * 60.0);
        int sec = (int) (((sweDate.getHour() - Math.floor(hour)) * 60.0 - Math
                .floor(min)) * 60.0);
        return "DOB:(DD:MM:YY) "+day+":"+month+":"+year+" TOB:(HH:MM:SS) "+hour+":"+min+":"+sec;
    }

download the Swiss Ephemeris library and enjoy coding!!!

like image 44
Nandan Kumar Singh Avatar answered Nov 04 '22 19:11

Nandan Kumar Singh