当前位置: 首页>>代码示例>>Java>>正文


Java TimeUnit.toMinutes方法代码示例

本文整理汇总了Java中java.util.concurrent.TimeUnit.toMinutes方法的典型用法代码示例。如果您正苦于以下问题:Java TimeUnit.toMinutes方法的具体用法?Java TimeUnit.toMinutes怎么用?Java TimeUnit.toMinutes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.TimeUnit的用法示例。


在下文中一共展示了TimeUnit.toMinutes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: formatTimeInterval

import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
private static String formatTimeInterval(long time, String format){
	TimeUnit c = TimeUnit.MILLISECONDS;
	
	long S = c.toSeconds(time);
	long M = c.toMinutes(time);
	long H = c.toHours(time);
	long D = c.toDays(time);

	long s = c.toSeconds(time - TimeUnit.MINUTES.toMillis(M));
	long m = c.toMinutes(time - TimeUnit.HOURS.toMillis(H));
	long h = c.toHours(time - TimeUnit.DAYS.toMillis(D));
	
	String r = format;
	r = r.replace("%S", "" + S);
	r = r.replace("%M", "" + M);
	r = r.replace("%H", "" + H);
	r = r.replace("%D", "" + D);
	r = r.replace("%s", (s > 9 ? "" : "0") + s);
	r = r.replace("%m", (m > 9 ? "" : "0") + m);
	r = r.replace("%h", (h > 9 ? "" : "0") + h);
	
	return r;
}
 
开发者ID:TBlueF,项目名称:RottenFood,代码行数:24,代码来源:RottenFood.java

示例2: formatTimeInterval

import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
/**
 * Convert from an amount of time to a string in the format xxd:hh:mm:ss
 * @param amount interval that needs to be formatted
 * @param timeUnit the unit of the interval
 * @return a formatted string representing the input interval
 */
public static String formatTimeInterval(long amount, TimeUnit timeUnit) {
	long totSeconds = timeUnit.toSeconds(amount);
	long seconds = totSeconds % 60;
	long totMinutes = timeUnit.toMinutes(amount);
	long minutes = totMinutes % 60;
	long totHours = timeUnit.toHours(amount);
	long hours = totHours % 24;
	long days = timeUnit.toDays(amount);
	String result = String.format("%02d:%02d", minutes, seconds);
	if (hours+days>0) {
		result = String.format("%02d:", hours) + result;
		if (days>0) {
			result = String.format("%dd:", days) + result;
		}
	}
	return result;
}
 
开发者ID:xtianus,项目名称:yadaframework,代码行数:24,代码来源:YadaUtil.java

示例3: durationToTimeString

import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
public static String durationToTimeString(long duration) {
	TimeUnit scale = TimeUnit.MILLISECONDS;
	long days = scale.toDays(duration);
	duration -= TimeUnit.DAYS.toMillis(days);
	long hours = scale.toHours(duration);
	duration -= TimeUnit.HOURS.toMillis(hours);
	long minutes = scale.toMinutes(duration);
	duration -= TimeUnit.MINUTES.toMillis(minutes);
	long seconds = scale.toSeconds(duration);
	return String.format("%d days, %d hours, %d minutes, %d seconds", days, hours, minutes, seconds);
}
 
开发者ID:Bleuzen,项目名称:Blizcord,代码行数:12,代码来源:Utils.java


注:本文中的java.util.concurrent.TimeUnit.toMinutes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。