我想将当前日期保存到我的 ListView 中的 TextView 我已经设置了所有其他内容所以不需要帮助只是将日期保存到 TextView 我的代码如下有人可以告诉我哪里错了吗?
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences.Editor editor = settings.edit();
editor.putLong("time", date.getTime());
editor.commit();
Date date2 = new Date(settings.getLong("time", 0));
最佳答案
Date 类的大部分方法已被弃用。您应该使用 Calendar 类。
日历 c = Calendar.getInstance();
要存储在您的 SharedPreferences 中,我建议您存储一个 long,它由 c.getTimeInMillis();
要获取此日期并将其存储在日历对象中,您应该放置 c.setTimeInMillis(myTimeStoredInSharedPreferences)
关于android - 将日期保存到共享首选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20748341/