嘿,我想在应用程序当前点击一个按钮但TIMESTAMP不正确时获取当前TIMESTAMP。 TIMESTAMP有时会显示时间,有时会提前10分钟。这里是代码获取时间戳错误的firebase android
timestapmReference.addValueEventListener(new ValueEventListener() {
public void onDataChange(DataSnapshot dataSnapshot) {
final long timeStampLong = (long) dataSnapshot.child("time").child("timestampQuestionSeen").getValue();
final DatabaseReference questionSeenReference = FirebaseDatabase.getInstance().getReference().child("users").child(uid).child("questions").
child(imagename);
questionSeenReference.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (!dataSnapshot.hasChild("questionSeen")) {
questionSeenReference.child("questionSeenTime").setValue(timeStampLong);
questionSeenReference.child("questionSeen").setValue("1");
}
questionSeenReference.removeEventListener(this);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
timestapmReference.removeEventListener(this);
}
public void onCancelled(DatabaseError databaseError) {
}
});
timestapmReference.child("time").child("timestampQuestionSeen").setValue(ServerValue.TIMESTAMP);
您是在模拟器上还是在真实设备上测试您的应用程序? –
我在真实设备上测试它@AlexMamo –
使用'ServerValue.TIMESTAMP'是设置时间戳的核心方式,正如我所看到的,您的代码看起来很好。您的日期和时间是否正确设置在您的手机上?检查您的手机设置并将其与计算机的时间进行比较。 –