Advertisement
Guest User

compare between Time.now() with constant time

a guest
Jun 26th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. private Boolean isStudentLate() {
  2. boolean studentLate = false;
  3. try {
  4. String inTime = "07:15";
  5. SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
  6. Date parsedInTime = sdf.parse(inTime);
  7. SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm", Locale.getDefault());
  8. Date currentTime = new Date();
  9. Integer currentTimeInt = Integer.getInteger(dateFormat.format(currentTime));
  10. Integer inTimeInt = Integer.getInteger(dateFormat.format(parsedInTime));
  11. if (currentTimeInt != null && inTimeInt != null) {
  12. Log.d("AppUtils", "currentTimeInt " + currentTimeInt + "\ninTimeInt " + inTimeInt);
  13. if (currentTimeInt > inTimeInt) {
  14. studentLate = true;
  15. }
  16. } else {
  17. Log.e("AppUtils", "currentTimeInt OR inTimeInt is NULL");
  18. }
  19. } catch (Exception ex) {
  20. Log.e("AppUtils", "Error " + ex);
  21. }
  22.  
  23. return studentLate;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement