Julian day of the year in Java

后端 未结 9 1044
挽巷
挽巷 2020-11-30 12:12

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

9条回答
  •  青春惊慌失措
    2020-11-30 12:55

    You can also get the "Julian Date" or "Ordinal Date" this way:

    import java.util.Calendar;
    import java.util.Date;
    
    public class MyClass {
    
      public static void main(String[] args) {
        Calendar cal = Calendar.getInstance();
        LocalDate myObj = LocalDate.now();
        System.out.println(myObj);
        System.out.println("Julian Date:" + cal.get(Calendar.DAY_OF_YEAR));
    
      }
    }
    

提交回复
热议问题