本文整理汇总了Java中java.util.concurrent.TimeUnit.toString方法的典型用法代码示例。如果您正苦于以下问题:Java TimeUnit.toString方法的具体用法?Java TimeUnit.toString怎么用?Java TimeUnit.toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.TimeUnit
的用法示例。
在下文中一共展示了TimeUnit.toString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: timeQuantity
import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
/**
* Format a duration (Quantity of time) to human readable string
*
* @param duration The period to format
* @param targetUnit The target unit
* @return A string formatted as [amount] [i18n scalar descriptor]
*/
public String timeQuantity(Duration duration, TimeUnit targetUnit) {
switch (targetUnit) {
case DAYS:
long days = duration.getStandardDays();
return days + " " + i18n.getIfElse(MathUtils.isPlural(days), TIMEUNIT_DAYS, TIMEUNIT_DAY);
case HOURS:
long hours = duration.getStandardHours();
return hours + " " + i18n.getIfElse(MathUtils.isPlural(hours), TIMEUNIT_HOURS, TIMEUNIT_HOUR);
case MINUTES:
long minutes = duration.getStandardMinutes();
return minutes + " " + i18n.getIfElse(MathUtils.isPlural(minutes), TIMEUNIT_MINUTES, TIMEUNIT_MINUTE);
case SECONDS:
long seconds = duration.getStandardSeconds();
return seconds + " " + i18n.getIfElse(MathUtils.isPlural(seconds), TIMEUNIT_SECONDS, TIMEUNIT_SECOND);
default:
throw new UnsupportedOperationException("Quantifying " + targetUnit.toString() + " is not supported");
}
}
示例2: validateToken
import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
public boolean validateToken(String token, Integer loginTime, TimeUnit timeUnit) {
try {
String key = jasypt.decrypt(token);
String [] keyParts = key.split("\\|");
String strDate = keyParts[keyParts.length - 1];
Date date = format.parse(strDate);
Date currentTime = new Date();
long duration = currentTime.getTime() - date.getTime();
long diff;
if (timeUnit.equals(TimeUnit.MINUTES))
diff = TimeUnit.MILLISECONDS.toMinutes(duration);
else if (timeUnit.equals(TimeUnit.SECONDS))
diff = TimeUnit.MILLISECONDS.toSeconds(duration);
else
throw new UnsupportedOperationException(timeUnit.toString() + " not supported");
if (diff > loginTime)
return false;
return true;
}
catch (Exception exc) {
exc.printStackTrace();
return false;
}
}
示例3: constructReasonString
import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
@VisibleForTesting
public static String constructReasonString(long maxTime,
TimeUnit timeUnit) {
return "retries get failed due to exceeded maximum allowed time (" +
"in " + timeUnit.toString() + "): " + maxTime;
}