JAvaとC#時間の比較ある月の初日の転換など


c#   4      
 DateTime comp_entdt= DateTime.Parse(DateTime.Now.AddMonths(-4).ToShortDateString());
 DateTime comp_entdtfirst=comp_entdt.AddDays(1-comp_entdt.Day);
 
/**
		 *   の  を ります
		 * @return String	yyyy-MM-dd HH:mm:ss
		 */
	 public String getCurrentTime(){   
	        Date currentTime = new Date();   
	        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");   
	        String dateString = formatter.format(currentTime);   
	        return dateString;   
	    }






 /**
		 *          
		 * @return String	yyyy-MM-dd HH:mm:ss
		 */
	 public String getFiveMonthBefore(Short carrier){
		 String returnString=null;
		 SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		 Calendar calendar = Calendar.getInstance();
		 Date nowDate=new Date();
		 try {
			nowDate=formatter.parse(this.getCurrentTime());
		} catch (ParseException e) {
			e.printStackTrace();
		}
		 if(carrier==3){
			 calendar.setTime(nowDate);
			 calendar.add(Calendar.MONTH, -5);
			 returnString= formatter.format(calendar.getTime()); 
		 }else{
			 calendar.setTime(nowDate);
			 calendar.add(Calendar.MONTH, -4);
			 Calendar cal_temp = Calendar.getInstance();
			 cal_temp.clear();
			 cal_temp.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), 1);
			 returnString=formatter.format(cal_temp.getTime());
		 }

		 return returnString;
	 }



	 
 
/**
	 *   の  
	 * @param t1		  1
	 * @param t2		  2
	 * @return int	t1>t2 1 t1=t2 0  t1<t2 -1
	 */
	 public int timeCompare(String t1,String t2){   
	        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");   
	        Calendar c1=Calendar.getInstance();   
	        Calendar c2=Calendar.getInstance();   
	        try {   
	            c1.setTime(formatter.parse(t1));   
	            c2.setTime(formatter.parse(t2));   
	        } catch (Exception e) {   
	            e.printStackTrace();   
	        }   
	        int result=c1.compareTo(c2);   
	        return result;   
	    }