我的持续时间目前以双精度格式以秒为单位。我如何转换它显示,多少小时,分钟和秒。如果我除以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