Is it possible to store a Date
object using SharedPreferences
?
Actually in my code I have a String
variable, boolean
and Date
. Here is my function for storing all the objects except Date
. So how that can be done please suggest me?
private void SavePreferences() {
String key="1";
String value="hello";
int x=5;
Date currentDate=new Date();
SharedPreferences sharedPreferences = getPreferences(MODE_APPEND);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(key, value);
editor.putInt("2",5);
editor.commit();
}
So my question is how to store the Date
using SharedPreferences
?
And you can read a
Date
from preferences like this:you can store the date value using sharedpreferences like this way
Put
Date
as formattedString
, e.g.Or you can put millis as Long
Set Date Time
Get Date Time