我对 Java/Android 开发有点陌生,我需要比较两次。其中一个时间值存储在一个字符串中,另一个是当前系统时间(长) - 我怎样才能找出两个时间之间的差异(以毫秒为单位)并将其存储为一个数字?
编辑:
尝试#1(响应懒惰的忍者)
public class Rules extends Activity {
private String password;
private PendingIntent mPendingIntent;
String TIMELIMIT = "10";
TextView textSsid, textSpeed, textRssi, Time;
private static final int NOTIFY_ME_ID = 1337;
private int count = 0;
private NotificationManager notifyMgr = null;
public Handler mHandler = new Handler();
public long mStartRX = 0;
public long mStartTX = 0;
public long txBytes;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.rules);
String NDEF_PREF = "prefs";
SharedPreferences prefs = getSharedPreferences(NDEF_PREF,
Context.MODE_PRIVATE);
String name = prefs.getString("name", "");
String code = prefs.getString("corename", "");
String time = prefs.getString("time", "");
String ssid = prefs.getString("restricted", "");
Time = (TextView) findViewById(R.id.Time);
Time.setText(time);
String dtStart = "09:27:37";
SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
try {
Date date = format.parse(time);
} catch (ParseException e) {
e.printStackTrace();
}
Long convertedLong = date.getTimeInMillis();
long currentTimeLong = System.currentTimeMillis();
long difference = currentTimeLong - convertedLong;
String strDiff = String.valueOf(difference);
问题:
日期无法解析 Rules.java Java 问题