Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 SharedPrefs 中存储时间的最佳方法是什么。最好将其转换为 int 或字符串,因为在从 SharedPrefs 检索到时间后需要将时间转换回时间。
保存:
SharedPreferences prefs; SharedPreferences.Editor editor = prefs.edit(); editor.putLong("time", Date.getTime()); editor.commit();
检索:
Date myDate = new Date(prefs.getLong("time", 0));