1

I want to compare the current date with the day before and the day next date.

Here is how I get current date and upload to firestore:

java.util.Date utilDate = new java.util.Date();
java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());

Map<String, Object> map = new HashMap<>();
map.put("time", sqlDate);

db.collection("users").document(user.getUid()).update(map);

Firestore screenshot:

Firestore screenshot

To get date from firestore

db.collection("users")
                .document(user.getUid())
                .get()
                .addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
            @Override
            public void onComplete(@NonNull Task<DocumentSnapshot> task) {
                if (task.isSuccessful()) {
                    DocumentSnapshot document = task.getResult();
                    assert document != null;
                    if (document.exists()) {
                        Date userDate = document.getDate("time");                  
                    }
                }
            }
        });

Format of date Sun Apr 26 17:59:05 GMT+05:00 2020

I want to get the next date and the previous date. Something like below:

Previous date: Sat Apr 25 17:59:05 GMT+05:00 2020

Today date: Sun Apr 26 17:59:05 GMT+05:00 2020

Next date: Mon Apr 27 17:59:05 GMT+05:00 2020

Any suggest me how to get previous and next date from firestore using current date(uploaded to firebase).

Community
  • 1
  • 1
Marsad
  • 859
  • 1
  • 14
  • 35
  • 1
    Once you convert the timestamp from Firestore to a Date object, there are many ways to add time to it. For example: https://stackoverflow.com/q/428918 – Frank van Puffelen Apr 26 '20 at 14:35

0 Answers0