자바 생 성 날짜 차원 표

32017 단어 학습 블 로그

import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class DateUtil {

	private final static SimpleDateFormat shortSdf = new SimpleDateFormat("yyyy-MM-dd");
    private final static SimpleDateFormat longSdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");

	/**
	 *   +1
	 * @param specifiedDay
	 * @return
	 */
	public static String getNowDate(String specifiedDay) {
		Calendar c = Calendar.getInstance();
		Date date = null;
		try {
			date = new SimpleDateFormat("yyyyMMdd").parse(specifiedDay);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		c.setTime(date);
		int day = c.get(Calendar.DATE);
		c.set(Calendar.DATE, day + 1);
		String dayBefore = new SimpleDateFormat("yyyyMMdd").format(c.getTime());
		return dayBefore;
	}
	/**
     *         
     *
     * @return
     */
    public static int getWeekDay(String specifiedDay) {
    	Date date = null;
		try {
			date = new SimpleDateFormat("yyyyMMdd").parse(specifiedDay);
		} catch (ParseException e) {
			e.printStackTrace();
		}
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        int week_of_year = c.get(Calendar.DAY_OF_WEEK);
        week_of_year = week_of_year - 1;
        if (week_of_year == 0) {
        	week_of_year = 7;
        }
        return week_of_year;
    }
	/**
	 *       
	 * @param specifiedDay
	 * @return
	 */
	public static int getWeekofYear(String specifiedDay) {
		Calendar c = Calendar.getInstance();
		Date date = null;
		try {
			date = new SimpleDateFormat("yyyyMMdd").parse(specifiedDay);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		c.setTime(date);
		c.setFirstDayOfWeek(Calendar.MONDAY);
		int week = c.get(Calendar.WEEK_OF_YEAR);
		return week;
	}
	 /**
     *        
     *
     * @return
     */
    public static int getYearWeekIndex(String specifiedDay) {
    	Date date = null;
		try {
			date = new SimpleDateFormat("yyyyMMdd").parse(specifiedDay);
		} catch (ParseException e) {
			e.printStackTrace();
		}
        Calendar calendar = Calendar.getInstance();
        calendar.setFirstDayOfWeek(Calendar.MONDAY);
        calendar.setTime(date);
        return calendar.get(Calendar.WEEK_OF_YEAR);
    }
	/**
	 *   yyyymmdd
	 * @param start_day
	 * @return
	 * @throws ParseException
	 */
	public static String yyyymmdd(String start_day,String patten) throws ParseException{
		Date date= new SimpleDateFormat("yyyyMMdd").parse(start_day);
		return new SimpleDateFormat(patten).format(date);
	}
	/**
     *       
     *
     * @param date
     * @return
     */
    public static int getMDaycnt(String start_day) {
    	Date date = null;
		try {
			date = new SimpleDateFormat("yyyyMMdd").parse(start_day);
		} catch (ParseException e) {
			e.printStackTrace();
		}
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        int i = c.get(Calendar.DAY_OF_MONTH);
            return i;
    }
    
	/**
     *        :   1-10    11-20    21-31 
     *
     * @param date
     * @return
     */
    public static int getTenDay(String start_day) {
    	Date date = null;
		try {
			date = new SimpleDateFormat("yyyyMMdd").parse(start_day);
		} catch (ParseException e) {
			e.printStackTrace();
		}
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        int i = c.get(Calendar.DAY_OF_MONTH);
        if (i < 11)
            return 1;
        else if (i < 21)
            return 2;
        else
            return 3;
    }
    /**
     *        :   1-10    11-20    21-31 
     *
     * @param date
     * @return
     */
    public static String getTenDays(String start_day) {
    	Date date = null;
		try {
			date = new SimpleDateFormat("yyyyMMdd").parse(start_day);
		} catch (ParseException e) {
			e.printStackTrace();
		}
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        int i = c.get(Calendar.DAY_OF_MONTH);
        if (i < 11)
            return "  ";
        else if (i < 21)
            return "  ";
        else
            return "  ";
    }
    /**
     *        :      
     *
     * @param date
     * @return
     */
    public static int getTenDayscnt(String start_day) {
    	Date date = null;
		try {
			date = new SimpleDateFormat("yyyyMMdd").parse(start_day);
		} catch (ParseException e) {
			e.printStackTrace();
		}
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        int i = c.get(Calendar.DAY_OF_MONTH);
        if (i < 11){
        	return 10;
        } else if (i < 21) {
        	return 10;
        }else{
        	return  Integer.valueOf(getMonthEndTime(start_day).substring(6,8))-20;
        }
    }
    /**
     *       
     *
     * @return
     */
    public static int getQuarter(String start_day) {
    	Date date = null;
		try {
			date = new SimpleDateFormat("yyyyMMdd").parse(start_day);
		} catch (ParseException e) {
			e.printStackTrace();
		}
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        int currentMonth = c.get(Calendar.MONTH) + 1;
        int dt = 0;
        try {
            if (currentMonth >= 1 && currentMonth <= 3)
            	dt=1;
            else if (currentMonth >= 4 && currentMonth <= 6)
            	dt=2;
            else if (currentMonth >= 7 && currentMonth <= 9)
            	dt=3;
            else if (currentMonth >= 10 && currentMonth <= 12)
            	dt=4;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dt;
    }
    /**
     *         
     *
     * @return
     */
    public static int getQuarterCntday(String start_day) {
        int cnt_d=0;
       int q= getQuarter(start_day);
        if (q==1) {
        	start_day = start_day.substring(0,4);
        	start_day = getMonthEndTime(start_day+"0201");
        	cnt_d = getMDaycnt(start_day);
        	cnt_d=31+cnt_d+31;
        }else if (q == 2) {
        	cnt_d=30+31+30;
        }else if (q == 3) {
        	cnt_d=31+31+30;
        }else if (q == 4) {
        	cnt_d=31+30+31;
        }
        return cnt_d;
    }
    /**
     *         
     *
     * @return
     */
    public static int getYearCntday(String start_day) {
        int cnt_d=0;
       start_day = start_day.substring(0,4);
       start_day = getMonthEndTime(start_day+"0201");
       cnt_d = getMDaycnt(start_day);
       cnt_d=31+cnt_d+31+30+31+30+31+31+30+31+30+31;
       
        return cnt_d;
    }
    /**
     *    /     
     *
     * @return
     */
    public static int getHyearCntday(String start_day) {
        int cnt_d=0;
       int q= getHalfYear(start_day);
        if (q==1) {
        	start_day = start_day.substring(0,4);
        	start_day = getMonthEndTime(start_day+"0201");
        	cnt_d = getMDaycnt(start_day);
        	cnt_d=31+cnt_d+31+30+31+30;
        }else if (q == 2) {
        	cnt_d=31+31+30+31+30+31;
        }
        return cnt_d;
    }
    /**
     *      /   
     *
     * @return
     */
    public static int getHalfYear(String start_day) {
        int dt = getQuarter(start_day);
        if (dt<=2) {
        	dt=1;
        }else if (dt>2) {
        	dt=2;
        }
        return dt;
    }
    public static String getHalfYears(String start_day) {
        int dt = getQuarter(start_day);
        if (dt<=2) {
        	return "   "; 
        } 
        	return "   "; 
    }
    /**
     *          
     *
     * @return
     */
    public static String getMonthStartTime(String start_day) {
    	Date date = null;
		try {
			date = new SimpleDateFormat("yyyyMMdd").parse(start_day);
		} catch (ParseException e) {
			e.printStackTrace();
		}
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        String dt = "";
        try {
            c.set(Calendar.DATE, 1);
            dt = new SimpleDateFormat("yyyyMMdd").format(c.getTime());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dt;
    }
    /**
     *        
     *
     * @return
     */
    public static String getMonthEndTime(String start_day) {
    	Date date = null;
		try {
			date = new SimpleDateFormat("yyyyMMdd").parse(start_day);
		} catch (ParseException e) {
			e.printStackTrace();
		}
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        String dt = "";
        try {
            c.set(Calendar.DATE, 1);
            c.add(Calendar.MONTH, 1);
            c.add(Calendar.DATE, -1);
            dt = new SimpleDateFormat("yyyyMMdd").format(c.getTime());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dt;
    }

    /**
     *         ,  
     *
     * @return
     */
    public static String getWeekStartTime(String start_day,String pattern) {
    	Date date = null;
		try {
			date = new SimpleDateFormat("yyyyMMdd").parse(start_day);
		} catch (ParseException e) {
			e.printStackTrace();
		}
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        try {
            int weekday = c.get(Calendar.DAY_OF_WEEK) - 2;
            c.add(Calendar.DATE, -weekday);
            c.setTime(longSdf.parse(shortSdf.format(c.getTime()) + " 00:00:00.000"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new SimpleDateFormat(pattern).format(c.getTime());
    }

    /**
     *          ,  
     *
     * @return
     */
    public static String getWeekEndTime(String start_day,String pattern) {
    	Date date = null;
		try {
			date = new SimpleDateFormat("yyyyMMdd").parse(start_day);
		} catch (ParseException e) {
			e.printStackTrace();
		}
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        try {
            int weekday = c.get(Calendar.DAY_OF_WEEK);
            c.add(Calendar.DATE, 8 - weekday);
            c.setTime(longSdf.parse(shortSdf.format(c.getTime()) + " 23:59:59.999"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new SimpleDateFormat(pattern).format(c.getTime());
    }
    /**
     *          
     *
     * @param date
     * @return
     */
    public static String getTenDayStartTime(String start_day) {
    	Date date = null;
		try {
			date = new SimpleDateFormat("yyyyMMdd").parse(start_day);
		} catch (ParseException e) {
			e.printStackTrace();
		}
        int ten = getTenDay(start_day);
            if (ten == 1) {
                return getMonthStartTime(start_day);
            } else if (ten == 2) {
                SimpleDateFormat df = new SimpleDateFormat("yyyyMM11");
                return df.format(date);
            } else {
                SimpleDateFormat df = new SimpleDateFormat("yyyyMM21");
                return df.format(date);
            }
 
    }
 
    /**
     *          
     *
     * @param date
     * @return
     */
    public static String getTenDayEndTime(String start_day) {
    	Date date = null;
		try {
			date = new SimpleDateFormat("yyyyMMdd").parse(start_day);
		} catch (ParseException e) {
			e.printStackTrace();
		}
        int ten = getTenDay(start_day);
            if (ten == 1) {
                SimpleDateFormat df = new SimpleDateFormat("yyyyMM10");
                return df.format(date);
            } else if (ten == 2) {
                SimpleDateFormat df = new SimpleDateFormat("yyyyMM20");
                return df.format(date);
            } else {
                return getMonthEndTime(start_day);
            }
    }
    /**
     *          
     *
     * @return
     * @throws ParseException 
     */
    public static String getQuarterStartTime(String start_day) throws ParseException {
    	Date date = null;
		try {
			date = new SimpleDateFormat("yyyyMMdd").parse(start_day);
		} catch (ParseException e) {
			e.printStackTrace();
		}
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        int currentMonth = c.get(Calendar.MONTH) + 1;
        String dt = "";
        try {
            if (currentMonth >= 1 && currentMonth <= 3)
                c.set(Calendar.MONTH, 0);
            else if (currentMonth >= 4 && currentMonth <= 6)
                c.set(Calendar.MONTH, 3);
            else if (currentMonth >= 7 && currentMonth <= 9)
                c.set(Calendar.MONTH, 6);
            else if (currentMonth >= 10 && currentMonth <= 12)
                c.set(Calendar.MONTH, 9);
            c.set(Calendar.DATE, 1);
            dt =  new SimpleDateFormat("yyyyMMdd").format(c.getTime());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dt;
    }
 
    /**
     *          
     *
     * @return
     * @throws ParseException 
     */
    public static String getQuarterEndTime(String start_day) throws ParseException {
    	Date date = null;
		try {
			date = new SimpleDateFormat("yyyyMMdd").parse(start_day);
		} catch (ParseException e) {
			e.printStackTrace();
		}
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        int currentMonth = c.get(Calendar.MONTH) + 1;
        String dt = "";
        try {
            if (currentMonth >= 1 && currentMonth <= 3) {
                c.set(Calendar.MONTH, 2);
                c.set(Calendar.DATE, 31);
            } else if (currentMonth >= 4 && currentMonth <= 6) {
                c.set(Calendar.MONTH, 5);
                c.set(Calendar.DATE, 30);
            } else if (currentMonth >= 7 && currentMonth <= 9) {
                c.set(Calendar.MONTH, 8);
                c.set(Calendar.DATE, 30);
            } else if (currentMonth >= 10 && currentMonth <= 12) {
                c.set(Calendar.MONTH, 11);
                c.set(Calendar.DATE, 31);
            }
            dt = new SimpleDateFormat("yyyyMMdd").format(c.getTime());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dt;
    }
    
    /**
     *      
     *
     * @return
     * @throws Exception 
     * @throws ParseException 
     */
    public static int getJjr(String start_day,String j) throws Exception  {
    	String f[] = { "0101" , "0405" , "0501" , "1001" };
    	String sub=start_day.substring(4,8);
    	if (!"1".equals(j)) {
    		for (int k = 0 ; k < f.length ; k++ ) {
    			if(f[k].equals(sub)){
    				return 1;
    			}
    		}
    		return 0;
    	}else{
    		return 1;
    	}
    }
    /**
     *      
     *http://timor.tech/api/holiday?date=20190505
     * @return
     * @throws Exception 
     * @throws ParseException 
     */
    public static String getJjrname(String start_day) throws Exception  {
    	String f[] = { "0101" , "0405" , "0501" , "1001" };
    	String f1[] = { "   " , "   " , "   " , "   " };
    	String sub=start_day.substring(4,8);
    		for (int k = 0 ; k < f.length ; k++ ) {
    			if(f[k].equals(sub)){
    				return f1[k];
    			}
    		}
    		return "-";
    }

    /**
     *     
     *
     * @return
     * @throws Exception 
     * @throws ParseException 
     */
    public static int iswork(String start_day,String j) throws Exception  {
    	String f[] = { "0101" , "0405" , "0501" , "1001" };
    	String sub=start_day.substring(4,8);
    	if ("0".equals(j) || "2".equals(j)) {
    		for (int k = 0 ; k < f.length ; k++ ) {
    			if(f[k].equals(sub)){
    				return 0;
    			}
    		}
    		return 1;
    	}else{
    		return 0;
    	}
    }
	/**
	 *     
	 * @param start_day
	 * @param end_day
	 * @return
	 * @throws Exception 
	 */
	public static void anyDate(String start_day,String end_day,int i) throws Exception {
		//int i = 0;
		while (true) {
			i++;
			start_day = getNowDate(start_day);
			if (start_day.equals(end_day)) {
				break;
			}else{
				System.out.println(start_day);
				StringBuffer rel = new StringBuffer();
				//Thread.sleep(500);
				int id=i;//     id 
				String year_s=start_day.substring(0, 4);
				String month_s=start_day.substring(4, 6);
				String day_s=start_day.substring(6, 8);
				String day_code = start_day;//      yyyymmdd
				String day_long_desc = yyyymmdd(day_code,"yyyy MM dd ");//       yyyy MM dd 
				String day_medium_desc =  yyyymmdd(day_code,"dd ");//        dd 
				String day_short_desc =  yyyymmdd(day_code,"yyyy-MM-dd");//     yyyy-MM-dd
				int  ws=getWeekofYear(day_code);
				String n_year=year_s;
				if (ws==1 && "12".equals(month_s)){
					n_year=(Integer.valueOf(year_s)+1) + "";
				}
				String week_code = n_year + "W" + ws;//      2019W02
				String week_long_desc = n_year + "  " + ws + " ";          //     String  2019  02  
				String week_medium_desc  = " " + ws + " ";                  //      String   02  
				 String week_short_desc = n_year + "-W" + ws ;               //   String 
				 String week_name =  yyyymmdd(day_code,"EEEE");                                   
				 //   String 
				 String ten_day_code =year_s + month_s + "X" + getTenDay(start_day);              
				 //     String 
				 String ten_day_long_desc = year_s +" "+ month_s + " " + getTenDays(start_day); 
				 //      String 
				 String ten_day_medium_desc = getTenDays(start_day);                              
				 //   String 
				 String ten_day_short_desc = year_s +"-"+ month_s + "-X" + getTenDay(start_day); 
				 //   String 
				 String month_code = year_s + month_s;                                        
				 //     String 
				 String month_long_desc = year_s + " " + month_s + " ";
				 //      String 
				 String month_medium_desc = month_s + " ";                                   
				 //   String 
				 String month_short_desc = year_s + "-" + month_s;                            
				 //   String 
				 String qu=getQuarter(start_day)+"";
				 String quarter_code = year_s +"Q"+qu;                     
				 //     String 
				 String quarter_long_desc = year_s + "  " + qu + "  "; 
				 //      String 
				 String quarter_medium_desc = " " + qu + "  "; 
				 //   String 
				 String quarter_short_desc = year_s + "-Q" + qu; 
				 //    String 
				 String half_year_code =year_s + "H" + getHalfYear(start_day); 
				 //      String 
				 String half_long_desc = year_s + " " +getHalfYears(start_day); 
				 //       String 
				 String half_medium_desc = getHalfYears(start_day); 
				 //    String 
				 String half_short_desc = year_s + "-H" + getHalfYear(start_day); 
				 //   String 
				 String year_code = year_s; 
				 //     String 
				 String year_long_desc = year_s + " "; 
				 //      String 
				 String year_medium_desc = year_s + " "; 
				 //   String 
				 String year_short_desc = year_s; 
				 //      String 
				 String all_time_code = "ALL"; 
				 //      String 
				 String all_time_desc = "ALL_TIME"; 
				 //     String 
				 String day_timespan = "1"; 
				 //    String 
				 String day_end_date = start_day; 
				 //    String 
				 String week_timespan = "7"; 
				 //     String 
				 String week_end_date = getWeekEndTime(start_day,"yyyy-MM-dd");; 
				 //    String 
				 String ten_day_timespan = getTenDayscnt(start_day)+""; 
				 //     String 
				 String ten_day_end_date = getTenDayEndTime(start_day); 
				 //    String 
				 String month_timespan = getMonthEndTime(start_day).substring(6,8)+""; 
				 //     String 
				 String month_end_date = getMonthEndTime(start_day); 
				 //    String 
				 String quarter_timespan = getQuarterCntday(start_day)+""; 
				 //     String 
				 String quarter_end_date = getQuarterEndTime(start_day); 
				 //     String 
				 String half_year_timespan = getHyearCntday(start_day)+""; 
				 //      String 
				 String half_year_end_date = year_s + "0630"; 
				 //    String 
				 String year_timespan = getYearCntday(start_day)+""; 
				 //     String 
				 String year_end_date = year_s + "1231"; 
				 //     String 
				 String week_start_date = getWeekStartTime(start_day,"yyyyMMdd"); 
				 //     String 
				 String month_start_date = getMonthStartTime(start_day); 
				 //      String 
				 String quarter_start_date = getQuarterStartTime(start_day); 
				 //     :1.  0.  
				 String workday_flag = getWeekDay(start_day) <=5 ? "1" : "0" ; 
				 //    :1.  0.  
				 String weekend_flag = getWeekDay(start_day) >5 ? "1" : "0"; 
				 String  getWorkDays = getWorkDays(start_day);/*0     1      2        3   */
				 //       1: ,0:  
				 String holiday_flag = getJjr(start_day,getWorkDays)+"";
				 //     String 
				 String holiday_name = getJjrname(start_day); 
				 //     1: ,0:  
				 Date d=new Date();
					String y=new SimpleDateFormat("yyyy").format(d);//   
					int ys=Integer.valueOf(y)+1;//  
					 String is_workday ="";
				 if (Integer.valueOf(year_s) < 2016 || Integer.valueOf(year_s)>=Integer.valueOf(ys) ) {
					 is_workday = getWeekDay(start_day) <=5 ? "1" : "0";
				 }else{
					 is_workday = iswork(start_day,getWorkDays) + "";
				 }
				  
				 String load_time = "2019-06-26 12:00:00";  //    
				 String last_week_day = getWeekEndTime(start_day,"yyyy-MM-dd"); //      String 
				 String last_month_day = yyyymmdd(getMonthEndTime(start_day),"yyyy-MM-dd"); //      String 
				rel.append(id+"\t");
				rel.append(day_code                +"\t");
				rel.append(day_long_desc           +"\t");
				rel.append(day_medium_desc         +"\t");
				rel.append(day_short_desc          +"\t");
				rel.append(week_code               +"\t");
				rel.append(week_long_desc          +"\t");
				rel.append(week_medium_desc        +"\t");
				rel.append(week_short_desc         +"\t");
				rel.append(week_name               +"\t");
				rel.append(ten_day_code            +"\t");
				rel.append(ten_day_long_desc       +"\t");
				rel.append(ten_day_medium_desc     +"\t");
				rel.append(ten_day_short_desc      +"\t");
				rel.append(month_code              +"\t");
				rel.append(month_long_desc         +"\t");
				rel.append(month_medium_desc       +"\t");
				rel.append(month_short_desc        +"\t");
				rel.append(quarter_code            +"\t");
				rel.append(quarter_long_desc       +"\t");
				rel.append(quarter_medium_desc     +"\t");
				rel.append(quarter_short_desc      +"\t");
				rel.append(half_year_code          +"\t");
				rel.append(half_long_desc          +"\t");
				rel.append(half_medium_desc        +"\t");
				rel.append(half_short_desc         +"\t");
				rel.append(year_code               +"\t");
				rel.append(year_long_desc          +"\t");
				rel.append(year_medium_desc        +"\t");
				rel.append(year_short_desc         +"\t");
				rel.append(all_time_code           +"\t");
				rel.append(all_time_desc           +"\t");
				rel.append(day_timespan            +"\t");
				rel.append(day_end_date            +"\t");
				rel.append(week_timespan           +"\t");
				rel.append(week_end_date           +"\t");
				rel.append(ten_day_timespan        +"\t");
				rel.append(ten_day_end_date        +"\t");
				rel.append(month_timespan          +"\t");
				rel.append(month_end_date          +"\t");
				rel.append(quarter_timespan        +"\t");
				rel.append(quarter_end_date        +"\t");
				rel.append(half_year_timespan      +"\t");
				rel.append(half_year_end_date      +"\t");
				rel.append(year_timespan           +"\t");
				rel.append(year_end_date           +"\t");
				rel.append(week_start_date         +"\t");
				rel.append(month_start_date        +"\t");
				rel.append(quarter_start_date      +"\t");
				rel.append(workday_flag            +"\t");
				rel.append(weekend_flag            +"\t");
				rel.append(holiday_flag            +"\t");
				rel.append(holiday_name            +"\t");
				rel.append(is_workday              +"\t");
				rel.append(load_time               +"\t");
				rel.append(last_week_day           +"\t");
				rel.append(last_month_day);
				writeFile(rel);
			}
		}
		//System.out.println(rel);
		//return rel;
	}
	
	/**
	 *        
	 * @param day
	 * @return
	 * @throws Exception
	 */
	public static String  getWorkDays(String day) throws Exception {
		    /**1、    :http://api.goseek.cn/Tools/holiday?date=    
			2、    :           0,            1,               2,         3 
			3、       :     2017            ,            ,    1 ,      
			4、  :
			http://api.goseek.cn/Tools/holiday?date=20170528 
			    :
			{"code":10000,"data":1}     
			**/
		Date d=new Date();
		String y=new SimpleDateFormat("yyyy").format(d);//   
		int ys=Integer.valueOf(y)+1;//  
		/*2016                    */
		 if (Integer.valueOf(day)<20160101 || Integer.valueOf(day.substring(0,4))>=Integer.valueOf(ys)) {
			 return "0";
		 }
	       // String httpUrl = "http://apis.baidu.com/xiaogg/holiday/holiday";
	       // String httpUrl = "http://www.easybots.cn/api/holiday.php";
	        String httpUrl = "http://api.goseek.cn/Tools/holiday";
	        String fdate = "date=" +day;
	        String jsonResult = request(httpUrl, fdate);
	            //         
	           // if ("0".equals(jsonResult.trim())) {
	            //    return "1";
	            //}
	        return jsonResult.substring(21,22);
	    }
	
	/**
     * @param urlAll :    
     * @param httpArg :  
     * @return     
     */
    public static String request(String httpUrl, String httpArg) {
        BufferedReader reader = null;
        String result = null;
        StringBuffer sbf = new StringBuffer();
        httpUrl = httpUrl + "?" + httpArg;
        try {
            URL url = new URL(httpUrl);
            HttpURLConnection connection = (HttpURLConnection)url.openConnection();
            connection.setRequestMethod("GET");
            //   apikey HTTP header
           // connection.setRequestProperty("apikey", "abfa5282a89706affd2e4ad6651c9648");
            connection.connect();
            InputStream is = connection.getInputStream();
            reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
            String strRead = null;
            while ((strRead = reader.readLine()) != null) {
                sbf.append(strRead);
                sbf.append("\r
"); } reader.close(); result = sbf.toString(); } catch (Exception e) { e.printStackTrace(); } return result; } public static void writeFile(StringBuffer rel) { String file_path = "d:/test.txt" ; FileWriter fw_s = null; PrintWriter pw_s = null; try { File f_hive = new File(file_path);/* */ fw_s = new FileWriter(f_hive, true); pw_s = new PrintWriter(fw_s); pw_s.println(rel); pw_s.flush(); fw_s.flush(); } catch (IOException e) { e.printStackTrace(); } finally { if (pw_s != null) pw_s.close(); if (fw_s != null) { try { fw_s.close(); } catch (IOException e) { e.printStackTrace(); } } } } public static void main(String[] args) throws Exception { String start_day = "20220212";/** */ String end_day = "20400101";/** */ anyDate(start_day,end_day,4426);// - - ID System.out.println("success !"); ///System.out.println(getWorkDays("20130101")); } }

 
-- dim_date CREATE TABLE dim_date(   id string COMMENT '홈 키 id',    day code string COMMENT '일 코드',    day long desc string COMMENT '일 전체 이름',    day medium desc string COMMENT '일 중간 길이 명',    day short desc string COMMENT '일 단명',    week code string COMMENT '주간 코드',    week long desc string COMMENT '주 전체 이름',    week medium desc string COMMENT '주 중간 길이 이름',    week short desc string COMMENT '주간 단명',    week name 문자열 COMMENT '주 이름',    ten day code string COMMENT '순 코드',    ten day long desc string COMMENT '순 전체 이름',    ten day medium desc string COMMENT '순 중간 길이 명',    ten day short desc string COMMENT '순 단명',    month code string COMMENT '월 코드',    month long desc string COMMENT '달의 전체 이름',    month medium desc string COMMENT '달의 길이 이름',    month short desc string COMMENT '달의 짧 은 이름',    quarter code string COMMENT '계절 코드',    quarter long desc string COMMENT '시즌 전체 이름',    quarter medium desc string COMMENT '시즌 중간 길이 명',    quarter short desc string COMMENT '계절 단명',    half year code string COMMENT '반년 코드',    half long desc string COMMENT '반년 전체 이름',    half medium desc string COMMENT '반년 중간 길이 명',    half short desc string COMMENT '반년 단명',    year code string COMMENT '년 코드',    year long desc string COMMENT '년 전체 이름',    year medium desc string COMMENT '연 중 길이 명',    year short desc string COMMENT '연 단명',    all time code string COMMENT '모든 시간 코드',    all time desc string COMMENT '모든 시간 이름',    day timespan string COMMENT '일 시간 크로스 오 버',    day end date string COMMENT '종료 날짜',    week timespan string COMMENT '주간 일수',    week end date string COMMENT '주 종료 날짜',    ten day timespan string COMMENT '순 전 일수',    ten day end date string COMMENT '순 종료 날짜',    month timespan string COMMENT '월 별 일수',    month end date string COMMENT '월 종료 날짜',    quarter timespan string COMMENT '계절 별 일수',    quarter end date string COMMENT '시즌 종료 날짜',    half year timespan string COMMENT '반년 간 일수',    half year end date string COMMENT '반년 종료 날짜',    year timespan string COMMENT '연 차 일수',    year end date string COMMENT '년 종료 날짜',    week start date string COMMENT '주간 시작 날짜',    month start date string COMMENT '월 시작 시간',    quarter start date string COMMENT '분기 시작 시간',    workday flag string COMMENT '근무일 여부: 1. 0. 아니오',    weekend flag string COMMENT '주말 여부: 1. 0. 아니오',    holiday flag string COMMENT '가 공휴일 인지 1: 예, 0: 아니오',    holiday name string COMMENT '공휴일 이름',    is workday string COMMENT '출근 여부 1: 예, 0: 아니오',    load time string COMMENT '불 러 오 는 시간',    last week day string COMMENT '주의 마지막 날',    last month day string COMMENT '달의 마지막 날') COMMENT '날짜 차원 표' ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' STORED AS TEXTFILE;

좋은 웹페이지 즐겨찾기