我试图制作一个签入签出功能,用户在指定时间之前无法签入。在这个例子中,我会说他们要到晚上 10:00 才能办理入住
schedule_start string = 10:00 24 小时制
如果用户尝试在 10:00 之前签到,则会出现一个警告对话框,告诉他们要早点并尝试在 10:00 之前签到
我的问题是警报对话框总是出现,即使在指定的时间之后。
有人可以帮助我朝着正确的方向前进吗?
SimpleDateFormat parserSDF = new SimpleDateFormat("k:m");
try {
Date d = parserSDF.parse(schedule_start);
Calendar now = Calendar.getInstance();
Date CurrentTime = now.getTime();
if (d.before(CurrentTime)) {
tooearlytocheckin = new AlertDialog.Builder(
screen1.this).create();
WindowManager.LayoutParams lp = tooearlytocheckin.getWindow().getAttributes();
lp.dimAmount = .30f;
tooearlytocheckin.getWindow().setAttributes(lp);
tooearlytocheckin.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
tooearlytocheckin.setTitle(" WARNING");
tooearlytocheckin.setCancelable(false);
tooearlytocheckin.setMessage("It is still too early for you to check in." + " Try back at " + (schedule_start));
tooearlytocheckin.setButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
DefaultWidgetVisibilityGONE();
CancelInButtonInstructions(); // <--- Use this setting for displaying view after pressing Okay
vib.vibrate(40);
}
});
tooearlytocheckin.show();
if (d.after(CurrentTime)) {
CheckInToggleButtonInstructions();
}
}
} catch (java.text.ParseException e1) {
e1.printStackTrace();
}
}