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

Posted on 2008-11-12
Last Modified: 2012-08-13
Can some one help me in converting given date of format (mm/dd/yyyy) to Julian date of format (ddd) in Java. Thanks.
Question by:laxmareddyb
    LVL 1

    Expert Comment

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

    Author Comment

    I am looking at converting the given Input date  to Julian Date. Not Julian date to Normal date.
    LVL 1

    Accepted Solution

    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) {
       else {
         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

    LVL 12

    Expert Comment

    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?
    LVL 12

    Expert Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Hire Top Freelancers to Complete Java Projects

    Source the talented Expert Exchange community
    for top quality work on your Java projects.

    Hire the best. Collaborate easily. Get quality work.

    Suggested Solutions

    Title # Comments Views Activity
    how to extract window origin in spring 2 55
    nested interface 5 29
    java continue statement 10 51
    firstChar challenge 13 55
    For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
    Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
    Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
    This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    6 Experts available now in Live!

    Get 1:1 Help Now