【发布时间】:2018-08-11 09:34:58
【问题描述】:
我想按降序将数据保存在firebase数据库中,我发现解决方案是添加一个负值的timeStamp字段,但使用ServerValue.TIMESTAMP只保存值一种积极的方式,那么我怎样才能在我的 FireBase 中保存一个负时间戳:
型号代码:
public class Book{
Object createdTimestamp;
String nom_livre;
String desc_livre;
String prix_livre;
String id_book;
String id_user;
public Book() {
super();
}
public Book(String nom_livre, String desc_livre, String prix_livre, String id_book,String id_user, Object createdTimestamp) {
super();
this.nom_livre = nom_livre;
this.desc_livre = desc_livre;
this.prix_livre = prix_livre;
this.id_book = id_book;
this.id_user=id_user;
this.createdTimestamp= createdTimestamp;
}
@Exclude
public long getCreatedTimestampLong(){
return (long)createdTimestamp;
}
//other getters and setters
}
在 fireBase 中添加数据的代码,我的情况是我正在 addBookActivity 上创建一本书:
private void createBook(String nom_livre, String desc_livre,String prix_livre,Object createdTimestamp) {
bookInfos=new Book(nom_livre,desc_livre,prix_livre,idLivre,id, ServerValue.TIMESTAMP );
myRefBook.child(idBook).setValue(bookInfos);
}
【问题讨论】:
标签: android firebase-realtime-database timestamp