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


Java Duration.getStandardDays方法代码示例

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


在下文中一共展示了Duration.getStandardDays方法的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: computeStandardTotalPrice

import org.joda.time.Duration; //导入方法依赖的package包/类
@JsonIgnore
public void computeStandardTotalPrice() {

    DateTime dtBegin = new DateTime(begin);
    DateTime dtEnd = new DateTime(end);
    DateTime dayBegin = new DateTime(dtBegin.getYear(), dtBegin.getMonthOfYear(), dtBegin.getDayOfMonth(), 0, 0, 0);
    DateTime dayEnd = new DateTime(dtEnd.getYear(), dtEnd.getMonthOfYear(), dtEnd.getDayOfMonth(), 0, 0, 0);

    Duration duration = new Duration(dayBegin, dayEnd);
    double price = getAccommodation().getPricePerDay() * duration.getStandardDays();
    totalPrice = Math.round(price * 100) / 100;
}
 
开发者ID:remipassmoilesel,项目名称:simple-hostel-management,代码行数:13,代码来源:Reservation.java

示例4: WeekDifference

import org.joda.time.Duration; //导入方法依赖的package包/类
/**
 * Calculates the week difference between two dates, rounded down to the nearest integer
 * @param startDate the first date
 * @param endDate the second date
 * @return the difference in weeks between the dates
 */
public static int WeekDifference(DateTime startDate, DateTime endDate) {
    Duration d = new Duration(startDate.toInstant(), endDate.toInstant());

    return (int)(d.getStandardDays() / 7);
}
 
开发者ID:CMPUT301F17T13,项目名称:cat-is-a-dog,代码行数:12,代码来源:DateUtil.java


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