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


Java TimeUnit.toString方法代码示例

本文整理汇总了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");
  }
}
 
开发者ID:Juraji,项目名称:Biliomi,代码行数:26,代码来源:TimeFormatter.java

示例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;
    }
}
 
开发者ID:awslabs,项目名称:aws-photosharing-example,代码行数:33,代码来源:TokenGenerator.java

示例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;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:7,代码来源:RetryPolicies.java


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