0

我正在寻找一种解决方案来显示 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
4

2 回答 2

4

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

String seconds = "1785.16";
int sec = (int)Float.parseFloat(seconds);
System.out.format("%02d:%02d", sec / 60, sec % 60);
于 2012-10-19T14:33:18.047 回答
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);

它对对象更友好^^而且您可以轻松更改格式!

于 2012-10-19T15:31:45.390 回答