如何在java中得到本月的开始和结束时间(天)
发布网友
发布时间:2022-04-20 17:57
我来回答
共1个回答
热心网友
时间:2023-07-08 16:08
import java.util.Calendar;
import java.util.Date;
public class Test {
public static void main(String args[]) {
System.out.println(getLastDayOfMonth(new Date()));
}
public static Date getLastDayOfMonth(Date sDate1) {
Calendar cDay1 = Calendar.getInstance();
cDay1.setTime(sDate1);
final int lastDay = cDay1.getActualMaximum(Calendar.DAY_OF_MONTH);
Date lastDate = cDay1.getTime();
lastDate.setDate(lastDay);
return lastDate;
}
}