システムの現在の日付と比較して日付ピッカーからの日付を "dd/mm/yyyy"の形式で比較し、操作を適用したいcurrentdate.before(pickeddate)
。どうすればいい?日付ピッカーの日付と現在の日付の比較とbefore()関数の適用
0
A
答えて
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;
}