zoukankan      html  css  js  c++  java
  • 判断当前日期是否是当月数据



    /*
    * *获取当月的开始日期 *@author: lkf *@Date: 2017/9/13 11:16 */ public static Date getCurrentMonthStartTime() { SimpleDateFormat shortSdf = new SimpleDateFormat("yyyy-MM-dd"); Calendar c = Calendar.getInstance(); Date now = null; try { c.set(Calendar.DATE, 1); now = shortSdf.parse(shortSdf.format(c.getTime())); } catch (Exception e) { e.printStackTrace(); } return now; } /** *获取当月的结束日期 *@author: lkf *@Date: 2017/9/13 11:16 */ public static Date getCurrentMonthEndTime() { SimpleDateFormat shortSdf = new SimpleDateFormat("yyyy-MM-dd"); Calendar c = Calendar.getInstance(); Date now = null; try { c.set(Calendar.DATE, 1); c.add(Calendar.MONTH, 1); c.add(Calendar.DATE, -1); now = shortSdf.parse(shortSdf.format(c.getTime())); } catch (Exception e) { e.printStackTrace(); } return now; }
    public static void main(String[] args) {
            Date date = DateUtils.formatDate("2017-09-30","yyyy-MM-dd");
            Date a = getCurrentMonthStartTime();
            Date b = getCurrentMonthEndTime();
            if(date.getTime() >= a.getTime() && date.getTime() <= b.getTime()){
                System.out.println("是当月数据");
            }else{
                System.out.println("不是当月数据");
            }
        }

         首先获取当前月的开始日期和结束日期,然后用你要比较的日期去进行比较。直接上代码,简单易懂。为了防止以后经常用到就写到博客里面把保存咯。希望可以帮助大家减少开发时间。绝得好用就点个赞吧

        哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈

  • 相关阅读:
    程序员常用字体(vs2008字体修改方案)
    Struts 与 Velocity 的集成
    CheckBox Button
    WINDOWS MOBILE winnet开发心得
    Change background color of a UIAlertView
    Windows Mobile 自定义控件(一)
    ZNLog
    获取磁盘空间大小
    iPhone开发:UIImage的一系列操作
    Windows Mobile 自定义控件(二)
  • 原文地址:https://www.cnblogs.com/lkf-00889/p/7513998.html
Copyright © 2011-2022 走看看