android分钟:秒

时间:2012-10-19 14:21:42

标签: java android

我正在寻找一种解决方案,以显示minutes:seconds

1785.16 string android device的持续时间

在php中很简单:

<?php
$seconds = '1785.16';
$minutes = floor($seconds/60);
$secondsleft = $seconds%60;
if($minutes<10)
$minutes = "0" . $minutes;
if($secondsleft<10)
 $secondsleft = "0" . $secondsleft;
echo "$minutes:$secondsleft";
?>


This will display: 29:45

2 个答案:

答案 0 :(得分:4)

所以,我假设你有String seconds = "1785.16"。然后你可以这样做:

String seconds = "1785.16";
int sec = (int)Float.parseFloat(seconds);
System.out.format("%02d:%02d", sec / 60, sec % 60);

答案 1 :(得分:0)

另一种方法是这样的:

float seconds = Float.parseFloat("1785.16");
Date date = new Date((long)(seconds * 1000));
SimpleDateFormat formater = new SimpleDateFormat("mm:ss");
String formatedDate = formater.format(date);
android.util.Log.d("This will display:", formatedDate);

它更友好对象^^你可以轻松改变格式!