Java – Julian day of the year in Java

javajulian-date

I have seen the "solution" at http://www.rgagnon.com/javadetails/java-0506.html, but it doesn't work correctly. E.g. yesterday (June 8) should have been 159, but it said it was 245.

So, does someone have a solution in Java for getting the current date's three digit Julian day (not Julian date – I need the day this year)?

Thanks! Mark

Best Answer

DateFormat d = new SimpleDateFormat("D");
System.out.println(d.format(date));