该空间是个人实践过程中的总结,欢迎交流吐槽!

【脚本写作】Java:将秒转换为时分秒

上一篇 / 下一篇  2018-03-28 11:11:07 / 个人分类:Java

package com.jcloud;

public class Study {

    public static void main(String[] args) {
        long time = 1800l;
        Object[] timeObject = totalValueforTime(time);

        System.out.println(timeObject[0] + "小时" + timeObject[1] + "分" + timeObject[2] + "秒");
    }

    public static Object[] totalValueforTime(long value) {
        int hour = (int) value / 3600;
        int min = (int) (value % 3600 ) / 60;
        int second = (int) (value % 3600 ) % 60;

        Object[] bjects = new Object[]{hour, min, second};
        return objects;
    }
}


==========================================
补充:对于上述Object[]输出
            for (Object temp : objects) {
                System.out.print(temp);
                logger.printLog(temp.toString());
            }

TAG:

水印 引用 删除 puchonghui   /   2018-03-28 14:37:58
既然总秒数用了long,为啥时分秒不用long,一定要用int呢?int 和long不止3600倍的关系吧,这样写不会越界么
 

评分:0

我来说两句

我的栏目

日历

« 2024-03-23  
     12
3456789
10111213141516
17181920212223
24252627282930
31      

数据统计

  • 访问量: 17593
  • 日志数: 16
  • 建立时间: 2016-09-08
  • 更新时间: 2018-03-28

RSS订阅

Open Toolbar