getting firebase ServerValue.TimeSTAMP in wrong format, how to convert to Date?

Tags: , , ,

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


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() {
                public void onDataChange(DataSnapshot dataSnapshot) {
                    List notes = new ArrayList<>();
                    for (DataSnapshot noteDataSnapshot : dataSnapshot.getChildren()) {
                    String time = String.valueOf(ServerValue.TIMESTAMP);

            public void onCancelled(DatabaseError databaseError) {



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

// you can set TimeStamp to this reference like this

String timeAddedLong=ServerValue.TIMESTAMP.toString;


// get previous time added

ValueEventListner listner=ValueEventListner() {

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


Source: stackoverflow