zoukankan      html  css  js  c++  java
  • java获取当前月第一天和最后一天

    获取当前月第一天:
     
    
    /**
         * 获取当前月第一天
         * @param month
         * @return
         */
        public static String getFirstDayOfMonth(int month) {
            Calendar calendar = Calendar.getInstance();
            // 设置月份
            calendar.set(Calendar.MONTH, month - 1);
            // 获取某月最小天数
            int firstDay = calendar.getActualMinimum(Calendar.DAY_OF_MONTH);
            // 设置日历中月份的最小天数
            calendar.set(Calendar.DAY_OF_MONTH, firstDay);
            // 格式化日期
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            String firstDay = sdf.format(calendar.getTime())+" 00:00:00";
            return firstDay;
        }
     
    
    获取当前月最后一天:
     
    
    public static String getLastDayOfMonth(int month) {
            Calendar calendar = Calendar.getInstance();
            // 设置月份
            calendar.set(Calendar.MONTH, month - 1);
            // 获取某月最大天数
            int lastDay=0;
            //2月的平年瑞年天数
            if(month==2) {
                lastDay = calendar.getLeastMaximum(Calendar.DAY_OF_MONTH);
            }else {
                lastDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
            }
            // 设置日历中月份的最大天数
            calendar.set(Calendar.DAY_OF_MONTH, lastDay);
            // 格式化日期
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            String lastDay = sdf.format(calendar.getTime())+" 23:59:59";
            return lastDay;
        }
    

      

  • 相关阅读:
    cf3b(贪心)
    cf4b
    poj 1037(经典dp)
    网络流之SAP算法学习
    cf3d
    hdu 1572(dfs+最短路)
    hdu 1735(贪心)
    Elementary Methods in Number Theory Exercise 1.5.10
    Elementary Methods in Number Theory Exercise 1.5.12
    Elementary Methods in Number Theory Exercise 1.5.10
  • 原文地址:https://www.cnblogs.com/xianz666/p/14035080.html
Copyright © 2011-2022 走看看