java-我想使用ServerValue.Timestamp以长格式iam表示timestamp的值
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java-我想使用ServerValue.Timestamp以长格式iam表示timestamp的值,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1967字,纯文字阅读大概需要3分钟。
内容图文
![java-我想使用ServerValue.Timestamp以长格式iam表示timestamp的值](/upload/InfoBanner/zyjiaocheng/668/343ce1b89f2647ee8fcd363c297c7f95.jpg)
Iam使用ServerValue.TimeStamp并使用hashmap上传到Firebase
HashMap< String,Object> map = new HashMap();
map.put(“ timestamp”,ServerValue.TIMESTAMP);
但我需要长时间获取TimeStamp的值,而不必将其上传到Firebase
我试图将其强制转换为很长的时间,但始终会收到ClassCastException
Map<String, Object> currentTime = new HashMap<>();
currentTime.put("timestamp", ServerValue.TIMESTAMP);
return (long) currentTime.get("timestamp");
有帮助吗?
解决方法:
当我通过替换替换模型类进行小的更改时,它对我有用
Map<String , String> timestamp;
与
Object timestamp;
因为对象类是Java中所有类的父类,所以任何子类都可以正常工作,因为将值保存在firebase中就可以了,而检索值时,您只需要将此对象强制转换为Long
这是我用过的模特
public class UserModel {
private String name , phone, email, birthDate, userType, address;
Object timestamp;
// for firebase retrieving data
public UserModel() {
}
public UserModel(String name, String phone, String email, String birthDate, String userType, String address) {
this.name = name;
this.phone = phone;
this.email = email;
this.birthDate = birthDate;
this.userType = userType;
this.address = address;
//get Date from firebase server automatic
this.timestamp = ServerValue.TIMESTAMP;
}
public String getName() {
return name;
}
public String getPhone() {
return phone;
}
public String getEmail() {
return email;
}
public String getBirthDate() {
return birthDate;
}
public String getUserType() {
return userType;
}
public String getAddress() {
return address;
}
@Override
public String toString() {
String data = " user name" + this.name+" , user Address : "
+this.address+" , user phone "+this.phone+" , user email : "+this.email
+" , user birthdate : "+this.birthDate+" , user type : "+this.userType
+ " , registered time "+this.timestamp;
return data;
}
/* public String getLoginDate() {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.mmm'Z'");
Date date = new Date(si)
return ;
}*/
}
and i uploaded it in firebase successufly
and here is the reslt i recieved when download data from firebase
内容总结
以上是互联网集市为您收集整理的java-我想使用ServerValue.Timestamp以长格式iam表示timestamp的值全部内容,希望文章能够帮你解决java-我想使用ServerValue.Timestamp以长格式iam表示timestamp的值所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。