Java Time to String TimeToString(int time)

Here you can find the source of TimeToString(int time)

Description

Time To String

License

Open Source License

Declaration

public static String TimeToString(int time) 

Method Source Code

//package com.java2s;
/*/*  w w w .  j a  v a 2s . c o m*/
 *    AsTeRICS - Assistive Technology Rapid Integration and Construction Set
 * 
 * 
 *        d8888      88888888888       8888888b.  8888888 .d8888b.   .d8888b. 
 *       d88888          888           888   Y88b   888  d88P  Y88b d88P  Y88b
 *      d88P888          888           888    888   888  888    888 Y88b.     
 *     d88P 888 .d8888b  888   .d88b.  888   d88P   888  888         "Y888b.  
 *    d88P  888 88K      888  d8P  Y8b 8888888P"    888  888            "Y88b.
 *   d88P   888 "Y8888b. 888  88888888 888 T88b     888  888    888       "888
 *  d8888888888      X88 888  Y8b.     888  T88b    888  Y88b  d88P Y88b  d88P
 * d88P     888  88888P' 888   "Y8888  888   T88b 8888888 "Y8888P"   "Y8888P" 
 *
 *
 *                    homepage: http://www.asterics.org 
 *
 *         This project has been funded by the European Commission, 
 *                      Grant Agreement Number 247730
 *  
 *  
 *         Dual License: MIT or GPL v3.0 with "CLASSPATH" exception
 *         (please refer to the folder LICENSE)
 * 
 */

public class Main {
    public static String TimeToString(int time) {
        String timeAsString = "";
        int highnibble = time;
        int lownibble = highnibble % 16;
        highnibble = (highnibble - lownibble) / 16;
        double tempTime = Math.pow(2.0, highnibble) * lownibble * 0.25;
        double seconds = tempTime % 60;
        double minutes = (tempTime - seconds) / 60;
        minutes = minutes % 60;
        double hours = (tempTime - (minutes * 60) - seconds) / 3600;

        if (hours != 0) {
            timeAsString = hours + "h ";
        }

        if (minutes != 0 || hours != 0) {
            timeAsString += minutes + "m ";
        }

        timeAsString += seconds + "s";

        return timeAsString;
    }
}

Related

  1. timeToString(final Date date)
  2. timeToString(final long time)
  3. timeToString(int s)
  4. timeToString(int time)
  5. timeToString(int time)
  6. timeToString(int time)
  7. timeToString(java.util.Date date)
  8. timeToString(long time)
  9. timeToString(long time)