java中怎样获取本月第一个星期一

2024-11-21 22:39:51
推荐回答(3个)
回答1:

import java.util.Calendar;
import java.util.Date;

public class C {

public static void main(String[] args) {
Calendar cal = Calendar.getInstance();

cal.set(Calendar.DAY_OF_MONTH, 1);

int i = 1;
while(cal.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY){
cal.set(Calendar.DAY_OF_MONTH, i++);
}

Date firstMonday = cal.getTime();
System.out.println(firstMonday.toString());
}

}

回答2:

学习!

回答3:

表示关注