首页 > 解决方案 > setText firebase TimeStamp 到 Android 中的 TextView

问题描述

我正在从 Cloud Firestore 读取数据,其中之一是时间戳。那么如何在 SimpleDateFormat 的活动中将该时间戳设置为 TextView。

标签: javafirebasetimestampsimpledateformatsettext

解决方案


您可以先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;
}

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

textView.setText(getDate(timestamp));

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


推荐阅读