将一个毫秒数转换成时间段,如怎样123456789转换成x小时y分z秒,怎样处理简单,谢谢

解决方案 »

  1.   

    class test
    {
    public static void main(String args[])
    {
    long ms=101010;//毫秒
    long[] hms=toHMS(ms);
    System.out.println(hms[0]+" H "+hms[1]+" M "+hms[2]+" S");
    }
    /**
    *@param ms 为要转换的毫秒数
    *@return 返回h m s数组
    */
    public static long[] toHMS(long ms)
    {
    long s;//秒
    long h;//小时
    long m;//分钟
    h=ms/1000/60/60;
    m=(ms-h*60*60*1000)/1000/60;
    s=ms/1000-h*60*60-m*60;
    return new long[]{h,m,s};
    }
    }