-1

I am a Android studio beginner. May I ask how can I get the timestamp in android studio through Firebase in String?

The code that I have used for updating the timestamp as below.

  Map<String, Object> map = new HashMap<>();
  map.put("timestamp", ServerValue.TIMESTAMP);                                  
  queue.child(UserInfo).updateChildren(map);

Big thanks!!

Molly Sin
  • 41
  • 6
  • 1
    Possible duplicate of [How to save the current date/time when I add new value to Firebase Realtime Database](https://stackoverflow.com/questions/43584244/how-to-save-the-current-date-time-when-i-add-new-value-to-firebase-realtime-data) – Alex Mamo Mar 31 '18 at 14:55
  • Please check the duplicate to see how can you get the data from a Firebase database. – Alex Mamo Mar 31 '18 at 14:56

1 Answers1

0
You can do it:

public class MyTimeStamp {
    private Object timestamp;

    public MyTimeStamp() {

    }

    public Object getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(Object timestamp) {
        this.timestamp = timestamp;
    }
}
And so:

public static void start(Context context) {
    MyTimeStamp timeStamp = new MyTimeStamp();
    timeStamp.setTimestamp(ServerValue.TIMESTAMP);

    Log.d(TAG, "start: ", timeStamp.getTimestamp().toString());
}
  • Thank you for your advice. May I ask how can I get the timestamp value in String from Firebase? As it is currently in the error DatabaseException: Failed to convert value of type java.lang.Long to String Thanks!! – Molly Sin Mar 30 '18 at 14:08