I am making an app in which user can post information and while posting I am saving the time of the post by using ServerValue.TIMESTAMP
in the Firestore database.
The problem is that the time is getting saved in the database as map something like this
time:
.sv : "timestamp"
Here is a picture to my database at Firestore
Now I want to extract human readable date and time to display to the users in a RecyclerView
.
This is my model class through which i want to get the time but haven't included any data member yet because i don't know how to get it done.
public class PostDisplayModel extends TransferId{
public String teacherName;
public String topic;
PostDisplayModel(){}
public PostDisplayModel(String teacherName, String topic) {
this.teacherName = teacherName;
this.topic = topic;
}
public String getTeacherName() {
return teacherName;
}
public void setTeacherName(String teacherName) {
this.teacherName = teacherName;
}
public String getTopic() {
return topic;
}
public void setTopic(String topic) {
this.topic = topic;
}
}
Below is my Adapter Class
public class PostDisplayAdapter extends RecyclerView.Adapter<PostDisplayAdapter.ViewHolder> {
Context context;
List<PostDisplayModel> postsList;
PostDisplayAdapter(Context context,List<PostDisplayModel> postsList){
this.postsList = postsList;
this.context = context;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.post_display_blueprint,parent,false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
holder.headline.setText(postsList.get(position).getTopic());
holder.uploaderName.setText(postsList.get(position).getTeacherName());
final String id = postsList.get(position).id;
holder.mView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context,PostDisplayActivity.class);
intent.putExtra("id",id);
context.startActivity(intent);
}
});
}
@Override
public int getItemCount() {
return postsList.size();
}
class ViewHolder extends RecyclerView.ViewHolder{
View mView;
public TextView uploaderName, headline;
public TextView time; //this is the textview in which i want the time to get displayed
public ViewHolder(View itemView) {
super(itemView);
mView = itemView;
uploaderName = mView.findViewById(R.id.uploader_name);
headline = mView.findViewById(R.id.headline);
time = mView.findViewById(R.id.time); //getting id of the time textview
}
}
}
I want a correct format of that timestamp like yyyy-MM-dd hh:mm:ss in textview, I am getting every other data correctly from the recycler view.
Any sort of suggestion/help will be appreciated.
Thanks in advance.