转换秒值小时分秒? [英] Convert seconds value to hours minutes seconds?

查看:218
本文介绍了转换秒值小时分秒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在想转换的秒值(一个BigDecimal变量)为一个字符串,一个EditText像1小时经济22分钟33秒什么样的。

I've been trying to convert a value of seconds (in a BigDecimal variable) to a string in an editText like "1 hour 22 minutes 33 seconds" or something of the kind.

我已经试过这样:

String sequenceCaptureTime = "";
BigDecimal roundThreeCalc = new BigDecimal("0");
BigDecimal hours = new BigDecimal("0");
BigDecimal myremainder = new BigDecimal("0");
BigDecimal minutes = new BigDecimal("0");
BigDecimal seconds = new BigDecimal("0");
BigDecimal var3600 = new BigDecimal("3600");
BigDecimal var60 = new BigDecimal("60");

(我有一个roundThreeCalc这是以秒为单位的价值,所以我试着在这里进行转换。)

(I have a roundThreeCalc which is the value in seconds so I try to convert it here.)

hours = (roundThreeCalc.divide(var3600));
myremainder = (roundThreeCalc.remainder(var3600));
minutes = (myremainder.divide(var60));
seconds = (myremainder.remainder(var60));
sequenceCaptureTime =  hours.toString() + minutes.toString() + seconds.toString();

然后,我设置EDITTEXT为sequnceCaptureTime字符串。 但是,这并不能正常工作。它的力量,每次关闭应用程序。我完全失去我的深度在这里,任何帮助是极大的AP preciated。快乐编码!

Then I set the editText to sequnceCaptureTime String. But that didn't work. It force closed the app every time. I am totally out of my depth here, any help is greatly appreciated. Happy coding!

推荐答案

您应该有更多的运气

hours = roundThreeCalc.divide(var3600, BigDecimal.ROUND_FLOOR);
myremainder = roundThreeCalc.remainder(var3600);
minutes = myremainder.divide(var60, BigDecimal.ROUND_FLOOR);
seconds = myremainder.remainder(var60);

这将每个部门的降幅​​十进制值。

This will drop the decimal values after each division.

编辑:如果没有工作,试试这个。 (我只是写和测试吧)

If that didn't work, try this. (I just wrote and tested it)

public static int[] splitToComponentTimes(BigDecimal biggy)
{
    long longVal = biggy.longValue();
    int hours = (int) longVal / 3600;
    int remainder = (int) longVal - hours * 3600;
    int mins = remainder / 60;
    remainder = remainder - mins * 60;
    int secs = remainder;

    int[] ints = {hours , mins , secs};
    return ints;
}

这篇关于转换秒值小时分秒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆