ChronoField.ALIGNED_WEEK_OF_MONTH
Вы можете использовать LocalDate.get()
и ChronoField.ALIGNED_WEEK_OF_MONTH
.
import java.time.LocalDate;
import java.time.temporal.ChronoField;
import java.time.temporal.TemporalAccessor;
/**
*
* @author Sedrick
*/
public class JavaApplication19 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
LocalDate localDate1 = LocalDate.of(1970, 01, 01);
LocalDate localDate2 = LocalDate.of(1970, 02, 01);
LocalDate localDate3 = LocalDate.of(1970, 01, 19);
LocalDate localDate4 = LocalDate.of(1970, 01, 31);
System.out.println(localDate1.get(ChronoField.ALIGNED_WEEK_OF_MONTH));
System.out.println(localDate2.get(ChronoField.ALIGNED_WEEK_OF_MONTH));
System.out.println(localDate3.get(ChronoField.ALIGNED_WEEK_OF_MONTH));
System.out.println(localDate4.get(ChronoField.ALIGNED_WEEK_OF_MONTH));
System.out.println(getOrdinalPosition(localDate4));
}
static public int getOrdinalPosition(TemporalAccessor temporal) {
return LocalDate.from(temporal).get(ChronoField.ALIGNED_WEEK_OF_MONTH);
}
}
Выход:
run:
1
1
3
5
5
BUILD SUCCESSFUL (total time: 0 seconds)