常用的日期方法总结

计算当前日期的下一天
/**
  * 找到日期date的后一天
  * @author mrsir
  * @param date
  * @return date
  */
 public static Date getLaterDay(Date date) { 
        Calendar calendar = Calendar.getInstance(); 
        calendar.setTime(date); 
        calendar.add(Calendar.DAY_OF_MONTH, 1); 
        date = calendar.getTime(); 
        return date; 
    }
判断给定日期是否是月末的一天
/**
     * 判断给定日期是否为月末的一天
     * @author mrsir
     * @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;
 }

 

 

测试例子:

 

<p>public class ceshiDateLixiao {</p><p> /**
  * @param args
  */
 @SuppressWarnings("deprecation")
 public static void main(String[] args) {
  
  SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");//小写的mm表示的是分钟  
  String dstr="2008-8-31";  
  java.util.Date date = null;
  try {
   date = sdf.parse(dstr);
  } catch (ParseException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }  
  
 
  boolean flag = ceshiDateLixiao.isLastDayOfMonth(date);
  System.out.println(flag);</p><p> }
 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; 
 } </p><p>
}
</p>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

李晓LOVE向阳

你的鼓励是我持续的不断动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值