Java Time to String time2string(double t)

Here you can find the source of time2string(double t)

Description

Converts double value of a time stamp to a string suitable for display.

License

Open Source License

Parameter

Parameter Description
t time value in hours.

Return

time string.

Declaration

public static String time2string(double t) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.text.NumberFormat;

public class Main {
    /**//from   w  w  w. j av a2  s. c  o  m
     * Converts double value of a time stamp to a string suitable for display.
     * @param t time value in hours.
     * @return time string.
     */
    public static String time2string(double t) {
        NumberFormat form = NumberFormat.getInstance();
        form.setMinimumIntegerDigits(2);
        form.setMinimumFractionDigits(0);
        form.setMaximumIntegerDigits(2);
        form.setMaximumFractionDigits(2);
        double stime = t;
        int hours = (int) Math.floor(stime);
        stime = (stime - hours) * 60;
        int min = (int) Math.floor(stime);
        stime = (stime - min) * 60;
        //int sec = (int)Math.floor(stime);
        return form.format(hours) + "h" + form.format(min) + "m" + form.format(stime) + "s";
    }
}

Related

  1. time2String(Date time)
  2. time2String(long time)
  3. timesAreEqual(Date date1, Date date2)
  4. timeStr(Date _Date)
  5. timeString()