Solution 1 :
It is a standard practice to store the time as the number of milliseconds since the Unix epoch. When retrieving you can format it into dd-mm-yy or any format you want by using this. You can use the same process to store it in the format you want. However, it isn’t recommended.
Problem :
I want to store current Date and time in firebase Database, But it is in millsec format.I want to save this in regular format i.e dd-mm-yy hr-ms.I am using SErverValue.Timestamp.
String id=databaseuser.push().getKey();
User user=new User(id,getname,getgenre,ServerValue.TIMESTAMP);
databaseuser.child(id).setValue(user);
Toast.makeText(this, "User Added!..", Toast.LENGTH_SHORT).show();
Comments
Comment posted by stackoverflow.com/a/9754625/6763544
Its better to store the time as you are doing now. When retrieving you can format it into dd-mm-yy or any format you want by using
Comment posted by amol junghare
Is there not any way to store like this
Comment posted by Sairaj Sawant
It’s a standard way of dealing with timestamps.Any specific reasons to store it as a string?
Comment posted by amol junghare
Ok…By seeing the data in firebase one can know the date and time very easily.So i am trying to do this
Comment posted by Sairaj Sawant
If you have “time” as the key & developers accessing the Firebase to “see” the data, it is evident that it’s a timestamp. So it’s better to implement standard practices.