【发布时间】:2018-02-20 08:31:02
【问题描述】:
我正在制作一个应用程序,用户可以在其中发布信息,并在发布时通过在 Firestore 数据库中使用 ServerValue.TIMESTAMP 来节省发布时间。
问题是时间正在数据库中保存为类似这样的地图
time:
.sv : "timestamp"
现在我想提取人类可读的日期和时间以在RecyclerView 中显示给用户。
这是我的模型类,我想通过它获得时间,但还没有包含任何数据成员,因为我不知道如何完成它。
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;
}
}
下面是我的适配器类
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
}
}
}
我想要一个正确格式的时间戳,例如 textview 中的 yyyy-MM-dd hh:mm:ss,我正在从回收站视图中正确获取所有其他数据。
我们将不胜感激任何形式的建议/帮助。
提前致谢。
【问题讨论】:
标签: java android firebase android-recyclerview google-cloud-firestore