如何获取某个日期是当月的最后一天
当前日期加一天,若当前日期与结果的月份不相同,就是最后一天。
取下一个月的第一天,下一个月的第一天-1
public static void main(String[] args)
{
Calendar c=Calendar.getInstance();
c.set(Calendar.YEAR,2004);
c.set(Calendar.MONTH,0);
c.set(Calendar.DAY_OF_MONTH,30);
Calendar c1=(Calendar)c.clone();
System.out.println(c.get(Calendar.YEAR)+” “+(c.get(Calendar.MONTH)+1)+” “+c.get(Calendar.DAY_OF_MONTH));
c.add(Calendar.DAY_OF_MONTH,1);
if(c.get(Calendar.MONTH)!=c1.get(Calendar.MONTH))
{
System.out.println(“是最后一天”);
}
else
{
System.out.println(“不是取后一天”);
}
}
取下一个月的第一天,下一个月的第一天-1
public static void main(String[] args)
{
Calendar c=Calendar.getInstance();
c.set(Calendar.YEAR,2004);
c.set(Calendar.MONTH,0);
c.set(Calendar.DAY_OF_MONTH,30);
Calendar c1=(Calendar)c.clone();
System.out.println(c.get(Calendar.YEAR)+” “+(c.get(Calendar.MONTH)+1)+” “+c.get(Calendar.DAY_OF_MONTH));
c.add(Calendar.DAY_OF_MONTH,1);
if(c.get(Calendar.MONTH)!=c1.get(Calendar.MONTH))
{
System.out.println(“是最后一天”);
}
else
{
System.out.println(“不是取后一天”);
}
}
【如何获取某个日期是当月的最后一天】相关文章
4. 如何将一个描述日期或日期/时间的字符串转换为一个Date对象
6. Java如何格式化日期
10. 把面试当做上班的第一天
本文来源:https://www.mianshiwenti.com/a12264.html
进入下载页面
上一篇:Jar包的作用是什么
下一篇:Java如何格式化日期