Java Time Format getFormattedTimeString(double s)

Here you can find the source of getFormattedTimeString(double s)

Description

get Formatted Time String

License

Open Source License

Declaration

public static String getFormattedTimeString(double s) 

Method Source Code

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

import java.text.DecimalFormat;

public class Main {
    private static DecimalFormat fmt = new DecimalFormat("##.###");

    public static String getFormattedTimeString(double s) {
        int hours = (int) s; // 10 ok
        int minutes = (int) ((s - hours) * 60); // 53 ok
        //      int seconds = (int) ((MTC - hours) * 3600 - minutes * 60 + 0.5); // 24 ok
        //      double seconds = Math.round(10.0*((s - hours) * 3600 - minutes * 60))/10.0; // 24 ok
        double seconds = (s - hours) * 3600 - minutes * 60; // 24 ok

        if (s < 0) {
            minutes = -minutes;/* w w  w.  ja v a 2  s.  co  m*/
            String ss = null;

            if (seconds < 10) {
                ss = "0" + fmt.format(-seconds);
            } else {
                ss = fmt.format(-seconds);
            }

            if (hours == 0) {
                return String.format("-%02d:%02d:", hours, minutes) + ss;
            }
            //         else {
            //         }
        }

        String ss = null;

        if (seconds < 10) {
            ss = "0" + fmt.format(seconds);
        } else {
            ss = fmt.format(seconds);
        }

        return String.format("%02d:%02d:", hours, minutes) + ss;

    }
}

Related

  1. getFormattedTime(Date date)
  2. getFormattedTime(Date date)
  3. getFormattedTime(final Calendar calendar)
  4. getFormattedTime(final Date date)
  5. getFormattedTimeFilesafe(long t)
  6. getFormatTime(Date date)
  7. getFormatTime(String format)
  8. getFormatTimeString(Date date, String pattern)
  9. getFullDateTimeFormat()