我有一部分代码可以找到用户以前保存的以毫秒为单位的保存时间。当时间从内存中取出然后由于某种原因转换为简单日期格式时,时间增加了 1 分钟。我不知道为什么会发生这种情况。以下是检索时间并进行转换的代码
time = PreferenceManager.getDefaultSharedPreferences(getBaseContext()).getFloat(String.valueOf(id)+"TIME", 0);
String dateString = new SimpleDateFormat("hh:mm a").format(new Date((long) time));
mPickedTimeText.setText(dateString);
以及节省时间的代码部分
this.time = time.getTimeInMillis();
PreferenceManager.getDefaultSharedPreferences(getBaseContext());
SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(getBaseContext());
Editor editor=prefs.edit();
editor.putFloat(String.valueOf(id)+"TIME", time);
editor.commit();
finish();
提前致谢!