那麼我想定義一個日期,並以秒爲單位查看與最近日期的差異。 下面是代碼我做活動的onCreate方法內:我如何計算預定義的日期時間和最近的日期時間之間的差異
txtNowTime = (TextView)findViewById(R.id.textViewNow);
SimpleDateFormat formata = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
String currentDateandTime = formata.format(new Date());
@SuppressWarnings("deprecation")
Date oldd = new Date("07/18/2014 11:12:13");
String olddt_frmt = formata.format(oldd);
long diff =0;
try {
Date d_recent = formata.parse("currentDateandTime");
diff = d_recent.getTime() - oldd.getTime();
} catch (ParseException ex) {
ex.printStackTrace(); }
txtNowTime.setText(String.valueOf(diff));
但它沒有顯示任何結果。 :-(
謝謝:-)我需要將差值除以1000 - 以秒爲單位。中R 18? – shaon007