- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
这是我的模型类:
import com.google.firebase.firestore.ServerTimestamp;
import java.util.Date;
public class YourModelClass {
private @ServerTimestamp Date timestamp;
YourModelClass() {}
public Date getTimestamp() {
return timestamp;
}
public void setTimestamp(Date timestamp) {
this.timestamp = timestamp;
}
@Override
public String toString() {
return "YourModelClass{" +
"timestamp=" + timestamp +
'}';
}
}
当我在日志中打印时,我得到了 null
Logger.info("Date", new YourModelClass()+"------"+new YourModelClass().getTimestamp() + "");
这是错误:
Output: 02-22 18:33:12.066 18980-18980/com.spendeye I/Date: YourModelClass{timestamp=null}------null
请让我知道解决方案。
最佳答案
这不是从数据库检索日期的正确方法。假设您使用 get()
调用,当检索 date
作为 Date
类型的对象时,您需要使用以下代码:
Date date = yourModelClass.getDate();
DateFormat dateFormat = SimpleDateFormat.getDateInstance(DateFormat.MEDIUM, Locale.US); //Or any other locale
String creationDate = dateFormat.format(date);
Log.d("TAG", creationDate);
如您所见,我正在使用从数据库获取的格式化日期,我没有创建类的新实例。您也可以在我的 tutorials 之一中看到这种方法。 其中我已逐步解释如何添加和显示日期。
关于java - @ServerTimestamp 在 Firebase Firestore 上始终为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48928362/
根据Firebase文档,我们不应该使用增量值,因为它可能会导致热点。我有多个子集合,并且我只对对子集合进行排序感兴趣,所以我希望将服务器端时间戳与文档ID(它表示我的子集合所在的文档)连接在一起。但
我有以下功能 Future _updateDocument(String path, {Map data}) async { final Map stampedData = {'updat
有没有办法在不使用云函数的情况下将时间添加到服务器时间戳? 我想要的是从面板更新时间戳,并让用户端检查时间戳是否大于当前时间。我还希望面板用户能够设置要添加的时间量,因此在用户端执行逻辑不是最佳解决方
在我的 Typescript 应用程序代码中,我定义了一个模型,该模型使用 Firestore 在服务器上生成的时间戳。当文档从数据库返回时,该字段将是一个 ISO 字符串。我想在我的整个应用程序中使
火力基地服务器时间戳 例如,对由firebase服务器生成的每个国家/地区应用相同的时间 session ...如果应用程序受一个国家/地区控制,那么服务器是否会应用该国家/地区的时间戳? 最佳答案
我正在 firestore 中构建一个实时聊天应用程序,我目前在读回消息时间戳时遇到问题。我正在使用 onSnapshot 监听器从我的消息集合中获取更新,但是我发现我在最新的时间戳上收到未定义的错误
我的 Firestore 数据库中有一个时间戳字段,格式如下:Quarta-feira, 11 de Outubro de 2017 às 10:24:54 GMT-03:00 定义为:map.p
我正在学习教程,代码中使用 firebase.firestore.FieldValue.serverTimestamp() 将 timestamp 属性设置为服务器时间戳。 import fireba
async createUser(uid: string, email: string) { await this.afs.doc(FirestoreDbConstant.USER_PROFI
我正在使用 TypeScript 在 Firebase 中为我的文档定义数据模型。创建文档时,createdOn字段将是服务器时间戳,否则它是一个日期。例如... export interface P
我需要有关此 Firebase 规则的帮助,我有一个存储时间戳的 child 而且我只需要在服务器时间戳小于存储在 Date->date 子节点上的时间戳时允许写入 firebase 的另一个位置。我
我想在 google cloud firestore 中创建一个查询来检索过去 10 小时内创建的数据,但我想使用服务器日期作为帐户的基础。 类似于: this.afs.collection("pos
我的 flutter 应用程序需要获取当前时间,我已经为此尝试了几个包,例如:truetime、ntptime、datetime 的 datetime、cloud firestore 的 Timest
刚好遇到这 block firebase doc在 firebase.firestore.SnapshotOptions 上: serverTimestamps serverTimestamps: "
我正在从 Cloud Firestore 读取一些数据(消息),并且在文档中我有一个 timestamp时间字段。 我有一个流: Stream get chats { return chatC
我找不到从 firestore 获取 serverTimestamp 的方法。无论是使用 firestore 本身,还是使用 angularfire。 我发现很多 github 问题都有解决方案,但不
我使用 Firestore 作为数据库,现在我想在用户注册时存储服务器时间戳。 来自 Firestore 文档 Map updates = new HashMap<>(); updates.p
如何检查客户端用户是否仅使用 firebase.firestore.FieldValue.serverTimestamp() 创建文档? 我有以下内容: allow create: if reques
这是我的模型类: import com.google.firebase.firestore.ServerTimestamp; import java.util.Date; public
firestore.FieldValue.serverTimestamp 与使用 Date.now()(从中央服务器)之间是否存在任何性能或功能差异? 最佳答案 如果您将客户端的 Date.now()
我是一名优秀的程序员,十分优秀!