我正在创建一个用于会员注册的应用程序我将 uesr 信息存储到 firestore 中。我的所有数据都作为字符串保存到 firestore 中,除了 join_date 之外,它保存为时间戳。但是当我检索这些数据时,它向我显示了这个错误
无法将 java.util.Date 类型的值转换为 String
我正在使用此代码保存当前日期(join_date)
members.put("join_date", FieldValue.serverTimestamp());
我在我的适配器中以字符串的形式检索这些数据
holder.mjoinDate.setText(mClip.get(position).getJoin_date());
您正在尝试在文本字段中设置日期对象。请尝试如下
例子:
String convertedString = convertDateToString(mClip.get(position).getJoin_date());
holder.mjoinDate.setText(convertedString);
private String convertDateToString (Date date) {
//change according to your supported formate
DateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
return dateFormat.format(date);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句