I am trying to compare the Time In or start time of the Subject and the current time. so for simple explanation, here's what I am trying to do..
if currentTime is beyond TimeIn, then I will toast a message "late", then if not beyond, then it will start a new activity.
in the image it shows the data and I am trying to get the pSubjtimeIn...
here is my code that I am trying...
String getSub = curSubj.getText().toString().trim();
dbref = FirebaseDatabase.getInstance().getReference("Subjects").child(getSub).child("pSubjtimeIn");
dbref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
if (snapshot.exists()) {
//I still got an error here Can't convert object of type java.lang.String to type
SectionClass data = snapshot.getValue(SectionClass.class);
if (data != null) {
String getTime = data.getpSubjtimeIn();
Toast.makeText(StudentHomePage.this, "" + getTime, Toast.LENGTH_SHORT).show();
if (getTime != null) {
SimpleDateFormat dateFormat = new SimpleDateFormat("h:mm a", Locale.getDefault());
Date storedTime = null;
try {
storedTime = dateFormat.parse(getTime);
} catch (ParseException e) {
e.printStackTrace();
}
if (storedTime != null) {
Calendar calendar = Calendar.getInstance();
Date currentTime = calendar.getTime();
calendar.setTime(storedTime);
calendar.add(Calendar.MINUTE, 15);
Date latetime = calendar.getTime();
if (currentTime.after(storedTime) && currentTime.before(latetime)) {
Toast.makeText(getApplicationContext(), "Late", Toast.LENGTH_SHORT).show();
} else {
Intent intent = new Intent(StudentHomePage.this, Present.class);
startActivity(intent);
}
}
}
}
}