2016-04-06 8 views

答えて

0

あなたがして、現在のを取得することができます:現在の日付を取得

String pattern = "MM-dd-yyyy"; 
SimpleDateFormat format = new SimpleDateFormat(pattern); 
try { 

    Date date = format.parse("01-07-2013"); 
    System.out.println(date); 

} catch (ParseException e) { 

e.printStackTrace(); 
} 
0

http://kiddyandroid.blogspot.in/2016/03/date-time-in-android.html

現在の日付のウィットを比較

private SimpleDateFormat dfDate = new SimpleDateFormat("yyyy-MM-dd"); 
public String getCurrentDate() { 
    int yr, month, day, hour; 
    Calendar today = Calendar.getInstance(); 
    yr = today.get(Calendar.YEAR); 
    month = today.get(Calendar.MONTH); 
    day = today.get(Calendar.DAY_OF_MONTH); 
    hour = today.get(Calendar.HOUR_OF_DAY); 
    return (yr + "-" + getLength(month + 1) + "-" + getLength(day)); 
} 

public static String getLength(int i) { 
    if (i > 9) 
     return "" + i; 
    return "0" + i; 
} 

h日付ピッカー日付:

String fromDate = yr + "-" + month + "-" + day; 
public boolean fromDateCheck(String fromDate) { 
    try { 
     String toDate = 12-02-2013 
     Date toDATE = dfDate.parse(toDate);  // dfDate --> Format of Date 
     Date fromDATE = dfDate.parse(fromDate); 

     if (fromDATE.before(toDATE) || fromDATE.compareTo(toDATE) == 0) { 
      // Do the things if FromDate(Current Date) and To Date are same or FromDate is not a Future date 
      return true; 
     } else if (fromDATE.after(toDATE)) { 
      Toast.makeText(this.context, "Invalid Date",Toast.LENGTH_SHORT).show(); 
      return false; 
     } else { 
      Toast.makeText(this.context, "Choose Correct Data", Toast.LENGTH_SHORT).show(); 
      return false; 
     } 
    } catch (Exception e) { 
    } 
    return false; 
}