将setText firebase TimeStamp转换为Android中的TextView

时间:2018-11-11 09:33:27

标签: java firebase timestamp simpledateformat settext

我正在从Cloud Firestore读取数据,其中之一是TimeStamp。因此,如何在SimpleDateFormat的活动中将TimeStamp设置为TextView。

1 个答案:

答案 0 :(得分:0)

您可以先使用以下代码将timeStamp转换为实际日期格式:

private String getDate(long time) {
    Calendar cal = Calendar.getInstance(Locale.ENGLISH);
    cal.setTimeInMillis(time);
    String date = DateFormat.format("dd-MM-yyyy", cal).toString();
    return date;
}

现在,您可以使用setText()方法将此日期设置为textView,并使用如下代码:

textView.setText(getDate(timestamp));

timeStamp可以是您从Firebase云Firestore中检索到的时间戳。