我的持續時間目前以雙精度格式以秒爲單位。我如何轉換它顯示,多少小時,分鐘和秒。如果我除以60就會有餘數。另外,我如何將我的double轉換爲Integer?如果我只是初始化我作爲整數,就會有一個錯誤:以小時,分鐘,秒鐘(以秒爲單位)獲取時間
"Type mismatch: cannot convert from double to int"` at "time=n*30+r1;"
* EDIT(對不起,我寫了錯誤的輸出):·讓說,秒爲132秒。我想在0小時,2分鐘12秒
double time = 0;
double hourTime=0;
double minTime=0;
btnStartMove.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
startButtonClicked=true;
startDistance=true;
counter= new MyCount(30000,1000);
counter.start();
btnStartMove.setText("Started...");
}
});
//button to get duration
btnDuration.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
if(startButtonClicked=true)
{
time=n*30+r1;
velocity=dist/time;
DecimalFormat df = new DecimalFormat("#.##");
Toast.makeText(MainActivity.this,"Duration :"+String.valueOf(time) + "Speed :"+String.valueOf(df.format(velocity)),Toast.LENGTH_LONG).show();
}
}
});
public class MyCount extends CountDownTimer{
public MyCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onFinish() {
counter= new MyCount(30000,1000);
counter.start();
n=n+1;
}
@Override
public void onTick(long millisUntilFinished) {
s1=millisUntilFinished;
r1=(30000-s1)/1000;
}
}}
您是否在尋找這雙d = 5.555d; int n =(int)d; – Rembo