本文整理匯總了Java中javax.xml.datatype.Duration.getDays方法的典型用法代碼示例。如果您正苦於以下問題:Java Duration.getDays方法的具體用法?Java Duration.getDays怎麽用?Java Duration.getDays使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.xml.datatype.Duration
的用法示例。
在下文中一共展示了Duration.getDays方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testNewDurationDayTimeLexicalRepresentation
import javax.xml.datatype.Duration; //導入方法依賴的package包/類
@Test
public void testNewDurationDayTimeLexicalRepresentation() throws DatatypeConfigurationException {
DatatypeFactory dtf = DatatypeFactory.newInstance();
Duration d = dtf.newDurationDayTime("P1DT23H59M65S");
int days = d.getDays();
Assert.assertTrue(days == 2, "Return value should be normalized");
}
示例2: testNewDurationDayTimeMilliseconds
import javax.xml.datatype.Duration; //導入方法依賴的package包/類
@Test
public void testNewDurationDayTimeMilliseconds() throws DatatypeConfigurationException {
DatatypeFactory dtf = DatatypeFactory.newInstance();
Duration d = dtf.newDurationDayTime(172805000L);
int days = d.getDays();
Assert.assertTrue(days == 2, "Return value should be normalized");
}
示例3: testNewDurationDayTimeBigInteger
import javax.xml.datatype.Duration; //導入方法依賴的package包/類
@Test
public void testNewDurationDayTimeBigInteger() throws DatatypeConfigurationException {
DatatypeFactory dtf = DatatypeFactory.newInstance();
BigInteger day = new BigInteger("1");
BigInteger hour = new BigInteger("23");
BigInteger min = new BigInteger("59");
BigInteger sec = new BigInteger("65");
Duration d = dtf.newDurationDayTime(true, day, hour, min, sec);
int days = d.getDays();
System.out.println("Days: " + days);
Assert.assertTrue(days == 2, "Return value should be normalized");
}
示例4: testNewDurationDayTimeInt
import javax.xml.datatype.Duration; //導入方法依賴的package包/類
@Test
public void testNewDurationDayTimeInt() throws DatatypeConfigurationException {
DatatypeFactory dtf = DatatypeFactory.newInstance();
Duration d = dtf.newDurationDayTime(true, 1, 23, 59, 65);
int days = d.getDays();
System.out.println("Days: " + days);
Assert.assertTrue(days == 2, "Return value should be normalized");
}
示例5: add
import javax.xml.datatype.Duration; //導入方法依賴的package包/類
/**
* 計算結束時間.
*/
public Date add(Date startDate, Duration duration) {
// 得到對應的時間
Calendar calendar = Calendar.getInstance();
calendar.setTime(startDate);
// 添加年數和月數,工作日方麵年和月的概念不會改變
calendar.add(Calendar.YEAR, duration.getYears());
calendar.add(Calendar.MONTH, duration.getMonths());
// 天數,小時,分鍾可能因為工作日有概念,所以特殊處理
int day = duration.getDays();
int hour = duration.getHours();
int minute = duration.getMinutes();
if (accurateToDay) {
// 有時需要自動把一天換算成8個小時,以實際計算工時
hour += (day * HOUR_OF_DAY);
day = 0;
} else {
Date workDate = this.findWorkDate(calendar.getTime());
calendar.setTime(workDate);
// 目前還沒有更好的算法,所以對天數累加,再判斷是否工作日
for (int i = 0; i < day; i++) {
calendar.add(Calendar.DATE, 1);
int originHour = calendar.get(Calendar.HOUR_OF_DAY);
int originMinute = calendar.get(Calendar.MINUTE);
// 如果當前就是工作日,就返回當前時間
// 如果當前的時間已經不是工作日了就返回最近的工作日
workDate = this.findWorkDate(calendar.getTime());
calendar.setTime(workDate);
calendar.set(Calendar.HOUR_OF_DAY, originHour);
calendar.set(Calendar.MINUTE, originMinute);
}
}
Date targetDate = calendar.getTime();
long millis = (hour * MILLIS_OF_HOUR) + (minute * MILLIS_OF_MINUTE);
DayPart dayPart = this.findDayPart(targetDate);
boolean isInbusinessHours = (dayPart != null);
if (!isInbusinessHours) {
DayPartResult dayPartResult = this.findTargetWorkDay(targetDate)
.findNextDayPartStart(0, targetDate);
targetDate = dayPartResult.getDate();
dayPart = dayPartResult.getDayPart();
}
Date end = dayPart.add(targetDate, millis);
return end;
}