Android Open Source - split Time Util






From Project

Back to project page split.

License

The source code is released under:

MIT License

If you think the Android project split listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.devfestco.split.Utils;
//from   w ww  .  j ava  2 s.  com
/**
 * Created by PaulTR on 6/29/14.
 */
public class TimeUtil {
    private static final String TWO_DIGITS = "%02d";

    private static final String ONE_DIGIT = "%01d";

    private static String _minutes;

    private static String _seconds;

    private TimeUtil() {}

    private static void setTime(long time) {
        String format;

        long seconds = time / 1000;
        long hundreds = (time - seconds * 1000) / 10;
        long minutes = seconds / 60;
        seconds = seconds - minutes * 60;
        long hours = minutes / 60;
        minutes = minutes - hours * 60;
        if (hours > 999) {
            hours = 0;
        }

        if (hundreds != 0) {
            seconds++;
            if (seconds == 60) {
                seconds = 0;
                minutes++;
                if (minutes == 60) {
                    minutes = 0;
                    hours++;
                }
            }
        }

        if (minutes >= 10 || hours > 0) {
            format = TWO_DIGITS;
            _minutes = String.format(format, minutes);
        } else {
            format = ONE_DIGIT;
            _minutes = String.format(format, minutes);
        }

        _seconds = String.format( TWO_DIGITS, seconds );
    }

    public static String getTimeString(long time) {
        setTime(time);
        return String.format("%s:%s", _minutes, _seconds);

    }
}




Java Source Code List

com.devfestco.split.IterationActivity.java
com.devfestco.split.Models.IterationListItem.java
com.devfestco.split.Services.TimerService.java
com.devfestco.split.Utils.TimeUtil.java