How to store a Date object in SharedPreferences?

Viewed 13732

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?

4 Answers
Related