I wrote a program to remove post from firebase. When currentDate == reference ("post"). Child (postKey) .child ("date") then post should be deleted. check passes each (new Thread) 24 hours I can’t understand why he doesn’t get post
private void deletePostFromFirebase(){
new Thread(new Runnable() {
@Override
public void run() {
while(true) {
try {
Thread.sleep(1000L*60L*60L*24L);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd MMM yyyy", Locale.ENGLISH);
Date date = new Date();
String newDate = simpleDateFormat.format(date);
DatabaseReference ref = FirebaseDatabase.getInstance().getReference("Posts");
ref.orderByChild("date").equalTo(newDate).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot itemSnapshot : dataSnapshot.getChildren()) {
itemSnapshot.getRef().removeValue();
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
throw databaseError.toException();
}
});
}catch (InterruptedException e){
showMessage(e.getMessage());
}
}
}
}).start();
}
I think that the date written in firebase (post.child -> date ' 30 апр 2020') is written in Russian format, and the current date that I get is written currentDate'30 april 2020 'english format. I think that this is a problem. Can someone explain this to me or is there another problem.