zoukankan      html  css  js  c++  java
  • 时间工具类:获取指定年、季、月的开始和结束时间

    public class DateUtils {
        private static SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
        
        public static String getFirstDayOfMonth(int year, int month) {
            Calendar cal = Calendar.getInstance();
            cal.set(Calendar.YEAR, year);
            cal.set(Calendar.MONTH, month - 1);
            cal.set(Calendar.DAY_OF_MONTH, cal.getMinimum(Calendar.DATE));
            return sf.format(cal.getTime())+" 00:00:00";
        }

        
        public static String getLastDayOfMonth(int year, int month) {
            Calendar cal = Calendar.getInstance();
            cal.set(Calendar.YEAR, year);
            cal.set(Calendar.MONTH, month - 1);
            cal.set(Calendar.DAY_OF_MONTH, 1);
            int value = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
            cal.set(Calendar.DAY_OF_MONTH, value);
            return sf.format(cal.getTime())+" 23:59:59";

        }
        
          
        public static String getFirstDayOfYear(int year){  
            Calendar calendar = Calendar.getInstance();  
            calendar.clear();  
            calendar.set(Calendar.YEAR, year);  
            Date currYearFirst = calendar.getTime();  
            return sf.format(currYearFirst)+" 00:00:00";
        }  
          
         
        public static String getLastDayOfYear(int year){  
            Calendar calendar = Calendar.getInstance();  
            calendar.clear();  
            calendar.set(Calendar.YEAR, year);  
            calendar.roll(Calendar.DAY_OF_YEAR, -1);  
            Date currYearLast = calendar.getTime();  
              
            return sf.format(currYearLast)+" 23:59:59";
        }  

       
        public static String getFirstDayOfSeason(int year, int season) {
            if(season == 1){
                return String.valueOf(year)+"-01-01 00:00:00";
            }else if(season == 2){
                return String.valueOf(year)+"-04-01 00:00:00";
            }else if(season == 3){
                return String.valueOf(year)+"-07-01 00:00:00";
            }else{
                return String.valueOf(year)+"-10-01 00:00:00";
            }
        }  
        
       
        public static String getLastDayOfSeason(int year, int season) {
            if(season == 1){
                return String.valueOf(year)+"-03-31 23:59:59";
            }else if(season == 2){
                return String.valueOf(year)+"-06-30 23:59:59";
            }else if(season == 3){
                return String.valueOf(year)+"-09-30 23:59:59";
            }else{
                return String.valueOf(year)+"-12-31 23:59:59";
            }
        }
        
        public static void main(String[] args) {
            String s = getFirstDayOfSeason(2013,2);
            String e = getLastDayOfSeason(2013,2);
            System.out.println(s);
            System.out.println(e);
        }
    }          

  • 相关阅读:
    CloudFoundry 中的GoRouter性能測试
    Android-SharedPreferences
    Oracle 闪回表实验
    使用Jfree实现吧条形图,java代码
    ZOJ Monthly, October 2010 ABEFI
    熟知CDN
    看,2015阿里巴巴视觉设计人员面临的问题招收学校
    于win7使用虚拟磁盘隐藏文件
    2015广东工业大学ACM学校巡回赛 I 游戏高手 (如压力dp)
    spring mvc 错误摘要--。位。
  • 原文地址:https://www.cnblogs.com/xxbcoder/p/5112587.html
Copyright © 2011-2022 走看看