在我的應用程序中有兩個按鈕。一個會顯示開始時間,第二個會顯示點擊時的停止時間。我需要得到這兩個值,計算差異並乘以另一個值。下面是我如何設置值的標籤之一:如何在android中獲得兩個時間差異
if (v == btnstart) {
Toast.makeText(getApplicationContext(), "Work Start", Toast.LENGTH_LONG).show();
Date d=new Date();
SimpleDateFormat sdf=new SimpleDateFormat("hh:mm a");
String currentDateTimeString = sdf.format(d);
txtstart.setText(currentDateTimeString);
}
您是否嘗試過尋找同樣的問題? http://stackoverflow.com/a/5127822/1178798 'long start = System.currentTimeMillis();長結束= System.currentTimeMillis(); long diff =結束 - 開始; DateTime dt = new DateTime(diff);' – zkristic