當前位置: 首頁>>代碼示例>>Java>>正文


Java Duration.getStandardHours方法代碼示例

本文整理匯總了Java中org.joda.time.Duration.getStandardHours方法的典型用法代碼示例。如果您正苦於以下問題:Java Duration.getStandardHours方法的具體用法?Java Duration.getStandardHours怎麽用?Java Duration.getStandardHours使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.joda.time.Duration的用法示例。


在下文中一共展示了Duration.getStandardHours方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: lengthBetween

import org.joda.time.Duration; //導入方法依賴的package包/類
/**
 * 獲得兩個時間點之間的時間跨度
 * 
 * @param time1
 *            開始的時間點
 * @param time2
 *            結束的時間點
 * @param timeUnit
 *            跨度的時間單位 see {@link JodaTime}
 *            (支持的時間單位有DAY,HOUR,MINUTE,SECOND,MILLI)
 */
public static long lengthBetween(DateTime time1, DateTime time2,
		DurationFieldType timeUnit) {
	Duration duration = Days.daysBetween(time1, time2).toStandardDuration();
	if (timeUnit == JodaTime.DAY) {
		return duration.getStandardDays();
	} else if (timeUnit == JodaTime.HOUR) {
		return duration.getStandardHours();
	} else if (timeUnit == JodaTime.MINUTE) {
		return duration.getStandardMinutes();
	} else if (timeUnit == JodaTime.SECOND) {
		return duration.getStandardSeconds();
	} else if (timeUnit == JodaTime.MILLI) {
		return duration.getMillis();
	} else {
		throw new RuntimeException(
				"TimeUnit not supported except DAY,HOUR,MINUTE,SECOND,MILLI");
	}
}
 
開發者ID:liuxuanhai,項目名稱:WeiXing_xmu-2016-MrCode,代碼行數:30,代碼來源:DateUtils.java

示例2: timeQuantity

import org.joda.time.Duration; //導入方法依賴的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

示例3: formatDuration

import org.joda.time.Duration; //導入方法依賴的package包/類
public static String formatDuration(String duration)
{
	Duration d = ISOPeriodFormat.standard().parsePeriod(duration).toStandardDuration();
	long hours = d.getStandardHours();
	Duration minusHours = d.minus(Duration.standardHours(hours));
	long minutes = minusHours.getStandardMinutes();
	long seconds = minusHours.minus(Duration.standardMinutes(minutes)).getStandardSeconds();
	String format = hours > 0 ? "%3$d:%2$02d:%1$02d" : "%2$d:%1$02d";
	return String.format(format, seconds, minutes, hours);
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:11,代碼來源:YoutubeUtils.java

示例4: digitalClockQuantity

import org.joda.time.Duration; //導入方法依賴的package包/類
/**
 * Format a duration in milliseconds to a digital clock string
 *
 * @param millis The amount of millis
 * @return A string: [hours:]minutes:seconds
 */
public String digitalClockQuantity(long millis) {
  Duration duration = new Duration(millis);
  Function<Long, String> pad = l -> StringUtils.leftPad(String.valueOf(l), 2, "0");

  long hours = duration.getStandardHours();
  long minutes = duration.getStandardMinutes() - (hours * 60);
  long seconds = duration.getStandardSeconds() - (minutes * 60 + hours * 3600);

  if (hours > 0) {
    return pad.apply(hours) + ':' + pad.apply(minutes) + ':' + pad.apply(seconds);
  }
  return pad.apply(minutes) + ':' + pad.apply(seconds);
}
 
開發者ID:Juraji,項目名稱:Biliomi,代碼行數:20,代碼來源:TimeFormatter.java


注:本文中的org.joda.time.Duration.getStandardHours方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。