[英]How to delete multiple images from firebase storage at a time in android studio
[英]How to save date and time in an orderly format Firebase & Android Studio
我正在创建一个社交应用程序,我想在有人上传帖子时保存帖子的日期和时间。 我希望将其保存为dd-MM-yyyy HH:mm:ss
。 目前这是它的样子
所以这是我在方法中的代码。
public static String getTimeDate(long timestamp){
try{
Date netDate = (new Date(timestamp));
SimpleDateFormat sfd = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss", Locale.getDefault());
return sfd.format(netDate);
} catch(Exception e) {
return "date";
}
}
我希望它能以我想要的格式保存帖子上传的日期和时间。 但我的问题是在 Firebase 数据库中正确上传它。 这就是我上传当前字段的方式。
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("postid", postid);
hashMap.put("postimage", myUrl);
hashMap.put("description", description.getText().toString());
hashMap.put("publisher", FirebaseAuth.getInstance().getCurrentUser().getUid());
我正在尝试上传时间戳,例如:
hashMap.put("date_time", getTimeDate() );
但是当我在getTimeDate()
旁边的括号上输入 hover 时,它说Expected 1 arguments but found 0
所以我猜我必须使用字符串而不是方法名称。 有人可以帮我做什么吗?
要在某人上传数据时获取当前时间,您可以从new Date()
更改您的方法而无需参数参数
public static String getTimeDate() { // without parameter argument
try{
Date netDate = new Date(); // current time from here
SimpleDateFormat sfd = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss", Locale.getDefault());
return sfd.format(netDate);
} catch(Exception e) {
return "date";
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.