当我保存使用Timestamp.now()的日期时间戳记时,它将为我保存此奇怪的映射而不是实际时间。我应该只获得位于数据/时间中的时间戳,而不是整个地图。奇怪的是,我实际上将一个名为date的时间戳而不是地图保存到Firestore。 这是图片:
这是我编写的将两次保存到Firestore的函数(两次是发明的名称,实际上表示注释)
private void saveTwice() {
String title = mTitle.getText().toString();
String description = mDescription.getText().toString();
Timestamp date = Timestamp.now();
Log.d(TAG, "saveTwice: " + date.toString());
if (title.trim().isEmpty() || description.trim().isEmpty()) {
Toast.makeText(this, "Please insert a title and description", Toast.LENGTH_SHORT).show();
return;
}
CollectionReference twiceRef = FirebaseFirestore.getInstance()
.collection("Twices");
twiceRef.add(new Twice(title, description, date));
Toast.makeText(this, "Twice added", Toast.LENGTH_SHORT).show();
Intent back = new Intent(AddTwice.this, MainActivity.class);
startActivity(back);
}
}
还有Twice.java。
package com.example.twicev11;
import android.text.format.DateFormat;
import com.google.firebase.Timestamp;
import com.google.firebase.firestore.FieldValue;
import java.util.Calendar;
import java.util.Locale;
public class Twice {
private String title, description;
private Timestamp date;
public Twice() {
//empty constructor needed
}
public Twice(String title, String description, Timestamp date) {
this.title = title;
this.description = description;
this.date = date;
}
public String getTitle() {
return title;
}
public String getDescription() {
return description;
}
public Calendar getDate() {
Calendar cal = Calendar.getInstance(Locale.getDefault());
cal.setTimeInMillis(date.toDate().getTime());
return cal;
}
}
我希望得到这个,而不是那个难看的地图