Julian day of the year in Java

Mark picture Mark · Jun 9, 2010 · Viewed 48.2k times · Source

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

Answer

mariami picture mariami · Jun 26, 2013
DateFormat d = new SimpleDateFormat("D");
System.out.println(d.format(date));