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


Java Hours.getHours方法代碼示例

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


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

示例1: getDeltaSinceEpoch

import org.joda.time.Hours; //導入方法依賴的package包/類
public static int getDeltaSinceEpoch(int time, int tempRes) {
    int delta = 0;
    
    // Epoch
    MutableDateTime epoch = new MutableDateTime();
    epoch.setDate(0);
    
    DateTime dt = new DateTime(time*1000, DateTimeZone.UTC);
    
    switch(tempRes) {
    case FrameworkUtils.HOUR:
        Hours hours = Hours.hoursBetween(epoch, dt);
        delta = hours.getHours();
        break;
    case FrameworkUtils.DAY:
        Days days = Days.daysBetween(epoch, dt);
        delta = days.getDays();
        break;
    case FrameworkUtils.WEEK:
        Weeks weeks = Weeks.weeksBetween(epoch, dt);
        delta = weeks.getWeeks();
        break;
    case FrameworkUtils.MONTH:
        Months months = Months.monthsBetween(epoch, dt);
        delta = months.getMonths();
        break;
    case FrameworkUtils.YEAR:
        Years years = Years.yearsBetween(epoch, dt);
        delta = years.getYears();
        break;
    default:
        hours = Hours.hoursBetween(epoch, dt);
        delta = hours.getHours();
        break;
    }
    
    return delta;
}
 
開發者ID:ViDA-NYU,項目名稱:data-polygamy,代碼行數:39,代碼來源:FrameworkUtils.java

示例2: hours_between_two_dates_in_java_with_joda

import org.joda.time.Hours; //導入方法依賴的package包/類
@Test
public void hours_between_two_dates_in_java_with_joda () {
	
	// start day is 1 day in the past
	DateTime startDate = new DateTime().minusDays(1);
	DateTime endDate = new DateTime();
	
	Hours hours = Hours.hoursBetween(startDate, endDate);
	int numberOfHours = hours.getHours();
	
	assertEquals(24, numberOfHours);
}
 
開發者ID:wq19880601,項目名稱:java-util-examples,代碼行數:13,代碼來源:HoursBetweenDates.java


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