Julian date to regular date conversion

date, java, julian-date

Solution

The Julian date for Nov 18 2013 is `"2013322"`. The number you used, `"2456606"`, would be the 606th day of 2456, which is Aug 28, 2457.

You might also have intended to use a different date format than `"yyyyD"` for your input. See http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html for information on possible codes.

Edit

The value that you used for the Julian date is the number of days since January 1, 4713 BCE. To get the Julian date using that system, you'll need to do something like the following:

String j = "2456606";
int day = Integer.parseInt(j) - x; // x == Jan 1, 1970 on the Gregorian
j = Integer.toString(day);
Date date = new SimpleDateFormat("D").parse(j);
String g = new SimpleDateFormat("dd.MM.yyyy").format(date);
System.out.println(g);

Where `x` is the Julian day corresponding to Jan 1, 1970 on the Gregorian calendar, i.e., the number of days elapsed between January 1, 4713 BCE and Jan 1, 1970.

Problem

How do i convert a julian date 2456606 which stands for Nov 18 2013 to the string format 18/11/2013 using java APIs? I tried executing the below code but it is not giving me the right answer. Any corrections to the below code are welcome ``` String j = "2456606"; Date date = new SimpleDateFormat("yyyyD").parse(j); String g = new SimpleDateFormat("dd.MM.yyyy").format(date); System.out.println(g); ```

Original source

Related problems