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

# 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
• 2
• 2
1 Solution

Commented:
Here is a cool little class from Real's How-to that converts to Julian:
0

Author Commented:
I am looking at converting the given Input date  to Julian Date. Not Julian date to Normal date.
0

Commented:
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);
}
``````
0

Commented:
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

Commented:
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.