Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
476 views
in Technique[技术] by (71.8m points)

java - Convert a Julian Date to Regular Calendar Date

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...