Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

This is how I am posting date to firebase:

final long PostTime = new Date().getTime();

and

mDatabaseUsers.child(userID).child("transdate").setValue(PostTime);

I am posting it successfully, and the date is shown like this

screenshot

I am able to fetch other data using this code:

String currentUid = FirebaseAuth.getInstance().getCurrentUser().getUid();
DatabaseReference uDatabaseReference = FirebaseDatabase.getInstance().getReference().child("Users");
uDatabaseReference.child(currentUid).addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
        String u_name = dataSnapshot.child("name").getValue().toString();
        String u_email = dataSnapshot.child("email").getValue().toString();
        int post_balance = dataSnapshot.child("balance").getValue(Integer.class);
        String bss = String.valueOf(post_balance);

        tvname.setText(u_name);
        tvemail.setText(u_email);
        tvbalance.setText(bss);
    }

    @Override
    public void onCancelled(DatabaseError databaseError) {
        throw databaseError.toException();
    }
});

My problem now is on date. I do not know how to fetch it. I want my date to show in this format: dd:MM:yyyy

How can I fetch the date from the firebase?

question from:https://stackoverflow.com/questions/65644129/how-to-retrieve-date-from-firebase-to-a-textview-android-studio

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
192 views
Welcome To Ask or Share your Answers For Others

1 Answer

First fetch your millisecond and convert to specific date format

long u_date_millis = dataSnapshot.child("date").getValue(Long.class);

SimpleDateFormat dateFormat = new SimpleDateFormat("dd:MM:yyyy");
String myPrintDate = dateFormat.format(new Date(u_date_millis )));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...