• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5667
  • 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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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