-1

I want to get Firebase Server current time, i searched stackoverflow, i found method ServerValue.TIMESTAMP and it's returning value when i debugged

.sv=timestamp

i am getting above String, but can't figure out how to convert it to date. I also tried getting it in hashmap, can somebody please help on this.

Note: i haven't stored date in firebase.

database.child("subscribers").addValueEventListener(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    List notes = new ArrayList<>();
                    for (DataSnapshot noteDataSnapshot : dataSnapshot.getChildren()) {
                    String time = String.valueOf(ServerValue.TIMESTAMP);
           }
                }
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });
Amir Dora.
  • 2,831
  • 4
  • 40
  • 61
  • Check **[this](https://stackoverflow.com/questions/43584244/how-to-save-the-current-date-time-when-i-add-new-value-to-firebase-realtime-data)** out. – Alex Mamo Jun 08 '18 at 07:37

1 Answers1

1

this psudo code may help you how to add time stamp to firebase and get it from firebase :

ref=FirebaseDatabase.getInstance().getReference().child("timeAdded");
// you can set TimeStamp to this reference like this

String timeAddedLong=ServerValue.TIMESTAMP.toString;

ref.setValue(timeAddedLong);


// get previous time added

ValueEventListner listner=ValueEventListner() {

public onDataChanged(DataSnap snap) {
    if(snap.value!=null) {
     long timeadded=parseToLong(snap.value.tostring)

     }
  ref.removeValueEventListner(this)
 }
}
ref.addValueEventListner(listner);
Zar Saeed
  • 100
  • 2
  • 13
  • the problem was i was not adding timestamp and trying to get it, i now understand that i have to first add timestamp then get it. Thanks – Amir Dora. Jun 08 '18 at 22:01