添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
/**
* 判断给定日期是否为月末的一天
*
* @param date
* @return true:是|false:不是
*/
public static boolean isLastDayOfMonth(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.DATE, (calendar.get(Calendar.DATE) + 1));
if (calendar.get(Calendar.DAY_OF_MONTH) == 1) {
return true;
}
return false;
}

亲测,可用,记得采纳

用Date类就可以实现

案列代码如下:

(1): mydate=new   Date();

myweekday=mydate.getDay();

mymonth=mydate.getMonth()+1;
myday=   mydate.getDate();
myyear=   mydate.getYear();
myhour   =   mydate.getHours();
if(mymonth<10)   mymonth="0"+mymonth;
year=(myyear   >   2000)   ?   myyear   :   1900   +   myyear;
if(myweekday   ==   0)
weekday="星期日";
else   if(myweekday   ==   1)
weekday="星期一";
else   if(myweekday   ==   2)
weekday="星期二";
else   if(myweekday   ==   3)
weekday="星期三";
else   if(myweekday   ==   4)
weekday="星期四";
else   if(myweekday   ==   5)
weekday="星期五";
else   if(myweekday   ==   6)
weekday="星期六";

(2):import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/** *//**
*
* @author zzk
*
*/
public class DateUtil {

/** *//**
* 取得某天相加(减)後的那一天
*
* @param date
* @param num(可正可负)
* @return
*/
public static Date getAnotherDate(Date date, int num) {
Calendar c = Calendar.getInstance();
c.setTime(date);
c.add(Calendar.DAY_OF_YEAR, num);
return c.getTime();
}

/** *//**
* 取得某月的的最后一天

*
* @param year
* @param month
* @return
*/
public static Date getLastDayOfMonth(int year, int month) {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, year);// 年
cal.set(Calendar.MONTH, month - 1);// 月,因为Calendar里的月是从0开始,所以要减1
cal.set(Calendar.DATE, 1);// 日,设为一号
cal.add(Calendar.MONTH, 1);// 月份加一,得到下个月的一号
cal.add(Calendar.DATE, -1);// 下一个月减一为本月最后一天
return cal.getTime();// 获得月末是几号
}