• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6953
  • Last Modified:

Convert given date (mm/dd/yyyy) to julian date (ddd) in java

Can some one help me in converting given date of format (mm/dd/yyyy) to Julian date of format (ddd) in Java. Thanks.
0
laxmareddyb
Asked:
laxmareddyb
  • 2
  • 2
1 Solution
 
patrick_defibaugh_chavezCommented:
Here is a cool little class from Real's How-to that converts to Julian:
http://www.rgagnon.com/javadetails/java-0506.html
0
 
laxmareddybAuthor Commented:
I am looking at converting the given Input date  to Julian Date. Not Julian date to Normal date.
0
 
patrick_defibaugh_chavezCommented:
Check out the toJulian function from that link:
public static double toJulian(int[] ymd) {
   int year=ymd[0];
   int month=ymd[1]; // jan=1, feb=2,...
   int day=ymd[2];    
   int julianYear = year;
   if (year < 0) julianYear++;
   int julianMonth = month;
   if (month > 2) {
     julianMonth++;
   }
   else {
     julianYear--;
     julianMonth += 13;
   }
   
   double julian = (java.lang.Math.floor(365.25 * julianYear)
        + java.lang.Math.floor(30.6001*julianMonth) + day + 1720995.0);
   if (day + 31 * (month + 12 * year) >= JGREG) {
     // change over to Gregorian calendar
     int ja = (int)(0.01 * julianYear);
     julian += 2 - ja + (0.25 * ja);
   }
   return java.lang.Math.floor(julian);
 }

Open in new window

0
 
marklorenzCommented:
This solution did not work correctly for me. E.g. yesterday (June 8) should have been 159, but it said it was 245.  Is there an error in this code from rgagnon?
0
 
marklorenzCommented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now