setText firebase TimeStamp 到 Android 中的 TextView
setText firebase TimeStamp to a TextView in Android
我正在从云 Firestore 读取数据,其中之一是时间戳。那么我如何在 SimpleDateFormat.
中的 activity 中将 TimeStamp 设置为 TextView
您可以先使用如下代码将 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 检索的时间戳。
我正在从云 Firestore 读取数据,其中之一是时间戳。那么我如何在 SimpleDateFormat.
中的 activity 中将 TimeStamp 设置为 TextView您可以先使用如下代码将 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 检索的时间戳。