java - setText firebase TimeStamp 到 Android 中的 TextView
问题描述
我正在从 Cloud Firestore 读取数据,其中之一是时间戳。那么如何在 SimpleDateFormat 的活动中将该时间戳设置为 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;
}
现在您可以使用方法将此日期设置为 textView setText()
,使用如下代码:
textView.setText(getDate(timestamp));
这里timeStamp
可以是您从 Firebase 云 Firestore 中检索到的时间戳。
推荐阅读
- oracle - 按日期范围对多列中的值求和
- installation - Inno Setup:复制文件(到 System32)需要很长时间
- angular - mat-button的Angular 6 Confirmation Dialog指令
- database - 我可以编写一个程序来查看 YugaByte 的 YCQL (Cassandra) api 中是否存在表吗?
- ios - iOS - MBProgressHUD bezelView 是透明的
- javascript - Laravel - Vue 和 Javascript 的问题
- c# - 刷新过期令牌 Web API
- node.js - heroku 上的节点 cron 作业,是否需要使用 heroku 调度程序?
- 3d - 合并相邻和共面的面
- outlook - 在 getMimeContent() 方法的情况下,您必须先加载或分配此属性,然后才能读取其值