Here you can find the source of toTimeStringForceShowHours(long millis, boolean showSeconds, boolean showUnits)
Parameter | Description |
---|---|
millis | the millis |
showSeconds | the show seconds |
showUnits | the show units |
public static String toTimeStringForceShowHours(long millis, boolean showSeconds, boolean showUnits)
//package com.java2s; /*//w w w . jav a 2s . c om * Copyright (c) 2016 Martin Pfeffer * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { /** * To time string force show hours string. * * @param millis the millis * @param showSeconds the show seconds * @param showUnits the show units * @return the string */ public static String toTimeStringForceShowHours(long millis, boolean showSeconds, boolean showUnits) { int h = (int) (millis / 1000) / 3600; int m = (int) (millis / 1000) % 3600 / 60; int s = (int) (millis / 1000) % 60; if (!showUnits) return showSeconds ? String.format("%02d:%02d:%02d", h, m, s) : String.format("%02d:%02d", h, m); else return showSeconds ? String.format("%02dh %02dmin %02ds", h, m, s) : String.format("%02dh %02dmin", h, m); } }