Get Date based on day count in Java

后端 未结 7 1188
感情败类
感情败类 2021-01-13 21:46

Simple Question, but Google surprisingly had little on this. I have the number of days from Jan 1st of the year. How can I convert that to a date i

7条回答
  •  长情又很酷
    2021-01-13 22:29

    If you are Android developer and using JodaTime this is how you get equivalent of this in java 8.

    LocalDate.ofYearDay("2020", 255).getDayOfWeek().getValue()
    

    Use this because ofYearDay is only supported above Android >= 26;

    MutableDateTime mutableDateTime1 = new MutableDateTime();
    mutableDateTime1.setYear("2020");
    mutableDateTime1.setDayOfYear(255);
    LocalDate.fromDateFields(mutableDateTime1.toDate()).getDayOfWeek();
    

提交回复
热议问题